- Home /
Controlling Animator through Script. I'm stuck please help!
I have been digging at this problem for a while and would greatly appreciate some insight. This may be long I am trying to add as much detail as possible.
BG INFO:
I am making an infinite runner kind of like jetpack joyride. I am stuck on making an animation that plays to warn the player there is a nearby obstacle approaching.
WHAT I HAVE TRIED:
I was first using an animation script but decided to go with the Animator instead. With the Animator I use the change material referance to make a flashing icon and its attached to a plane. So my current obstacle is a prefab. when the prefab is created I use the,
obstacle = Gameobject.Find("obstacle"); anim = obstacle.Getcomponent(); anim.Play("StartAnim");
(Sorry if codes not perfect its a lot of code from different scripts thought I'd simplify it)
Then on the prefab I use a code saying
if(transoform.position.x < animationplanepos){ anim.Play("StopAnim"); }
So obviously I switch to a different Animator State. I would like to just start and stop the animator completely ass opposed to having it keep running guessing in the long run it would cut down on memory but I have tried and failed. Now I think I have read about this problem elsewhere but cant remember but after about the third or fourth prefab instantiate everything seems to be working fine.
QUESTIONS:
Obviously, why doesnt the script work immediately but instead after 3 or 4 prefabs?
Is there possibly an easier or more effective way of achieving this goal.
I am also getting the "AnimationEvent has no function name specified!". In the add animation event window it doesn't give me an option to select a function I have no idea what this window is for.
Your answer
Follow this Question
Related Questions
Can't find Animator State/Invalid Layer Index in child object inside prefab 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Prefab animation only plays on first instance 1 Answer
Can't Check If Animatorstate Is In Second Layer 1 Answer
How do I render a prefab without any scripts/components running? 3 Answers