I am having problem to set something to a variable that is in another script, but in the same gameobject. Here is the part of my code that is giving me trouble
constructions[1] = (GameObject)PhotonNetwork.Instantiate ("Foundation", new Vector3 (transform.position.x + 3, transform.position.y, transform.position.z + 3), transform.rotation,0 );
gameObject.GetComponent<CharacterControllerMultiplayer> ().grabbedObject = constructions [1];
The object is being Instantiate just fine, but i can’t set it to the variable that is in another script.
The var grabbedObject is like this: public GameObject grabbedObject;
Even if i create something like an int in CharacterControllerMultiplayer and try to set it through the other script i get the error, which is btw: NullReferenceException : Object reference not set to an instance of an object.
Can someone tell me what am i doing wrong. I think that i am doing the wrong aproaching in the access things from another scripts.
Thank you!
Try to add this.gameObject in line two at the start. It may not recognize what gameObject you are referencing to.
– SnotE101