When I execute the next code, I see this error:
NullReferenceException: Object reference not set to an instance of an object
GameManager.Start () (at Assets/Scripts/GameManager.cs:15)
I need to change “velocity” variable, from another class.
The objects with tag “Block”, have a script component named “MoveManager.cs”
Should I provide more info?
public class MoveManager : MonoBehaviour {
int velocity = 2;
public void SetVelocity (int newVelocity) {
velocity = newVelocity;
}
}
==============================================================
public class GameManager : MonoBehaviour {
int road = 2;
MoveManager gameObj;
void Start (){
//next is line 15
gameObj = GameObject.FindGameObjectsWithTag ("Block").GetComponent<MoveManager> ();
InvokeRepeating ("ChangeRoad", 5, 5);
}
void ChangeRoad (){
road = Random.Range (1, 4);
//I can see a Debug here
gameObj.SetVelocity (road);
//I can't see a Debug here
}
}
Regards.