Hey guys.
I’m having some problems with getting a vector3 variable from another script.
public Vector3 krudtPosition;
In Update(), I’m running this next script through once, using a bool checking if it has just been done.
krudtPosition = new Vector3(30.50F,krudt.transform.position.y,krudt.transform.position.z);
This works fine when I debug it. The problem comes when I want to get it in another script.
First I define this.
public Grid krudtScript;
Grid is the name of the script where I want to get the vector3 from.
Then, in the Start() i do the following:
public GameObject krudt;
GameObject theKrudt = GameObject.Find("Krudt");
krudtScript = GetComponent("Grid") as Grid;
And lastly, I’m using it like this:
krudt.transform.position = krudtScript.krudtPosition;
I’ve also tried this, but to no luck:
krudt.transform.position = new Vector3(krudtScript.krudtPosition);
I’m getting this error:
NullReferenceException: Object reference not set to an instance of an object