A part of this script is suppose to change the InvokeRepeating timer depending on the player’s speed, it takes the value of the variable speed from a different script called PlayerMovement
using UnityEngine;
using System.Collections;
public class BlockSizeAndPosition : MonoBehaviour {
public int Distance;
public GameObject Player;
public GameObject[] Blocks = new GameObject[9];
private PlayerMovement MovementScript;
private float RespawnTimer;
void Awake() {
MovementScript = GetComponent<PlayerMovement>();
}
void Start() {
InvokeRepeating ("ChooseBlock", 1, RespawnTimer);
}
void Update() {
ChangeTimer();
}
void ChangeTimer() {
if (MovementScript.speed <= 2) {
RespawnTimer = 4;
} else if (MovementScript.speed >= 2 && MovementScript.speed <= 3) {
RespawnTimer = 3.5f;
//rest
//of
//script
This is the error I get
This is the PlayerMovement script
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float speed;
public float HorizontalMovementSpeed;
public float increment;
void Start() {
InvokeRepeating("ChangeSpeed", 5, 5);
}
void Update() {
transform.Translate (0, speed * Time.deltaTime, 0);
Vector3 Movement = new Vector3 (Input.GetAxis ("Horizontal"), 0, 0);
transform.position = transform.position + Movement * HorizontalMovementSpeed * Time.deltaTime;
}
void ChangeSpeed() {
if (speed <= 10) {
speed = speed + increment;
}
}
}
!(http://using UnityEngine; using System.Collections; public class PlayerMovement : MonoBehaviour { public float speed; public float HorizontalMovementSpeed; public float increment; void Start() { InvokeRepeating(“ChangeSpeed”, 5, 5); } void Update() { transform.Translate (0, speed * Time.deltaTime, 0); Vector3 Movement = new Vector3 (Input.GetAxis (“Horizontal”), 0, 0); transform.position = transform.position + Movement * HorizontalMovementSpeed * Time.deltaTime; } void ChangeSpeed() { if (speed <= 10) { speed = speed + increment; } } })