- Home /
Question by
$$anonymous$$ · Mar 30, 2015 at 09:45 AM ·
animationjavascriptcubedoor
Start Animation in code is not working
Hello, can you help me ? My animation isn't starting from my code:
coin = CoinControll.Coin;
var anim: Animation;
anim = GetComponent.<Animation>();
if (coin>0){
GetComponent.<Animation>().Play();
}
What is wrong ?
beztytułu.png
(37.8 kB)
Comment
I formatted your question for you... Please learn how to ask clear, well formatted questions.
There's a dot incorrectly positioned in the method call.
GetComponent<Animation>(); // Ins$$anonymous$$d of GetComponent.<Animation>()
It's UnityScript, the dot is correct (kinda ugly though ;) )
This code also has no structure to read correctly (is that in Update, or how is this even called?) Is coin ever greater than 0?
BTW. why GetComponent all the time if you already hold a reference with anim?
Answer by Cherno · Mar 30, 2015 at 01:43 PM
Just pass the animation name as a string as a parameter.
anim.Play("dooropen");