- Home /
Does a reference to a script have up-to-date info ?
Hey all, Just a quick question here. I'm trying to get out of the habit of doing SendMessage for absolutely everything, even if it is convenient. To expand on the Opening question; When I make a reference to a script, does the variable have up-to-date info every time I access it from the new script? i.e
private GameObject theHunter;
private MainObject theHunterCopy;
.........
theHunter = GameObject.FindGameObjectWithTag("Main");
theHunterCopy = (MainObject)theHunter.GetComponent("MainObject");
.........
if(theHunterCopy.Herbivores > 0){
float divideBy = (theHunterCopy.Herbivores) + .5f;
transform.localScale += new Vector3(.003f/divideBy, .003f/divideBy, .003f/divideBy);
}
.........
theHunterCopy.FSpawn--;
theHunterCopy.ReceiveEnergy(energy);
Thanks!
Answer by Landern · Dec 21, 2012 at 06:58 PM
Yes, when you find it, you are getting a reference to the game object, if in that game object, it has behaviors/scripts attached that are changing, say, it's position, then in the script that has the reference, it would have that "up-to-date" information. This of course doesn't apply to a deep clone of an object.
Thanks. I'm learning about the differences between Structures and Classes now. BTW, this is not the first time I get "you must log in as a different user" when trying to upvote an answers. Any idea what that is about.
Your answer
Follow this Question
Related Questions
updating variable of one script in other 1 Answer
Trying to access a variable from another script attached to same object. 1 Answer
Saving data 1 Answer
One script for all variables? 0 Answers
Need help with a raycast 1 Answer