I am trying to call a method of a class attached to a prefab that I have instantiated with the reference to the GameObject stored in an array.
What is happening is, I instantiate an instance of prefab Y, then store there references into a 2d array like so:
GameObject object = (GameObject) Instantiate(Y, someVec3, Quaternion.Identity);
object.name = "Name";
array[0,0] = object; // 2d array of GameObjects
Then I attempt to call a method from a script attached to the game object like this:
array[0,0].GetComponent<ScriptName>().TheMethod();
In my project, calling the method should render the game objects mesh by simply setting a boolean=true, then the scripts Update() method deals with it.
This is not occuring. If I set the boolean=true in the scripts Start() method and instantiate the prefab it works fine. I used a Debug.Log() call to see if the method is actually being called using the above code, and it is and indeed this boolean is being set to True. Yet nothing happens after that.
The update method is as follows:
void Update() {
if (flag) {
// Render
}
}
and the TheMethod() is as follow:
public void TheMethod() { flag = true; }
where flag has been declared as a private bool.
I am baffled as to why this is occuring. Thank you in advance for any advice/solutions!