I have a model that is set to be active with SetActiveRecursively(true); in the first script. As soon as this model is active I want a different script to set a variable “three” to 0. After that the variable has to be able to be changed by other parts of the script (if I put it in the update function it makes the variable always equal to 0). That way I can make it equal to 1 in another part of the script. Is there any way to do this?
1 Answer
1Your question is a bit confusing…mostly because of “I want a different script to set a variable ‘three’ to 0.” Does it need to be a different script? If it can be done in the same script you can use MonoBehaviour.OnEnable.
function OnEnable () {
three = 0;
Debug.Log("This script was just enabled");
}
The object with the first script is the camera and the second script is on the model(child object of camera). Thank you for helping me, this worked very well! I put this in the second script to reset the variable three to 0 when the object is active. Thanks for the help!
– MelonWarriorI converted my comment to a answer. If this answered your question, click on the checkmark to close it out.
– robertbu