- Home /
gameObject.tag doesn't work as I'd expect inside a function Update
When a boolean in objectAs script becomes true, I want objectBs tag to change into something.
The boolean changes to true for 5 and then back to false (this is controlled by a script attached to objectA), so what I want is to have my objectBs tag change after those 5. So I attach the following script to objectB:
function Awake () { gameObject.tag = "HeatOff"; // I set the objectBs tag to what I want }
function Update () { if (aScriptOfObjectA.boolTrue) // When the objectAs boolean is true... { gameObject.tag = "HeatOn"; //...I want objectBs tag to change to this } else // When the objectAs boolean goes back to false (this is controlled //by objectAs script...
{
gameObject.tag = "HeatOff"; //......I want objectBs tag to change to this
}
}
What happens is this: I press play and the objectBs tag instantly changes from Untagged to HeatOff.
When the objectAs boolean becomes true, the objectBs tag becomes HeatOn.
When the objectAs boolean reverts to false after 5, the objectBs tag stays HeatOn.
What am I missing here?
Why not let objectA's script manage the change of tag. Then ins$$anonymous$$d of objectB's script keeps checking every single frame, then objectA would control when to change it.
Thanks for commenting Ejlersen, it seems my scripting has other problems that cause things not to function as expected. I will change which script manages what. Sorry to all that bothered to read my question and many thanks!