The question, in short form:
I have a script that is trying to execute other gameObject’s animation (Through GameObject.Find(“objectName”)). When I try to execute the animation, turns out the Animation component for that GameObject is null. The animation is set in the original GameObject and I don’t have a way (Or the knwoledge) to tell if the returned GameObject actually is the GameObject I want the application to get.
Long version, with more specifics of my code:
I have “myScript.js”, the file from when I want to call a determined animation from a specific GameObject.
I have two GameObjects, “1stElem” and “2ndElem”, each one of them with an Animation attached and several animations on it. On of them is called “Retire”.
Then there is a third GameObject called “button”, with myScript.js attached to it.
When someone clicks on “1stElem” or “2ndElem”, a “global” variable stores it. After that, if someone clicks “button”, the onMouseDown function reads the global variable and does this:
var string = numeral(globalVariable);
var object = GameObject.Find(numeral+“Elem”);
To give some insight, “numeral” will return “1st” or “2nd” depending on the value of “globalVariable”. Then, object should get a reference to “1stElem” or “2ndElem” and customAnimate should play “Retire” from the start (time = 0) and at standard speed (speed = 1). I made customAnimate just to be able to play animations backwards and such with only one function call.
The problem is that the debugger is telling me that, after the second line of code executes, the “animation” component for “1stElem” (or “2ndElem”) is null. But the animation is present.