Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Animation won't start

$
0
0
I am reading "Unity 3.x game development essentials" and i am blocked at "adding the coconut shy shack" paragraph. I wrote all the code for make the target play an animation when it collides with a coconut, the code is good, but when i instantiate a coconut and it hits the target, the target won't start the animation. This is my code: #pragma strict private var beenHit:boolean=false; private var targetRoot:Animation; var hitSound:AudioClip; var resetSound:AudioClip; var resetTime:float = 3.0f; function Start () { targetRoot=transform.parent.transform.parent.animation; } function Update () { } function OnCollisionEnter(theObject:Collision){ if (beenHit==false && theObject.gameObject.name=="Coconut"){ StartCoroutine("targetHit"); } } function targetHit(){ audio.PlayOneShot(hitSound); targetRoot.Play("down"); beenHit=true; yield new WaitForSeconds(resetTime); audio.PlayOneShot(resetSound); targetRoot.Play("up"); beenHit=false; } this is my scene setting: [Image1][1] And this is my target's animations setting: [Image2][2] [1]: http://imageshack.com/a/img43/441/wb8v.png [2]: http://imageshack.com/a/img593/9297/ljgp.png

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>