Advertisement
Evilgit

Untitled

Jun 18th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. [RequireComponent (typeof(AudioSource))]
  5.  
  6. public class TargetCollision : MonoBehaviour
  7. {
  8.     bool beenHit = false;
  9.     Animation targetRoot;
  10.     public AudioClip hitSound;
  11.     public AudioClip resetSound;
  12.     public float resetTime = 3.0f;
  13.    
  14.     // Use this for initialization
  15.     void Start ()
  16.     {
  17.         targetRoot = transform.parent.transform.parent.animation;
  18.     }
  19.    
  20.     void OnCollsionEnter(Collision theObject)
  21.     {
  22.         if(beenHit == false && theObject.gameObject.name == "coconut")
  23.         {
  24.             StartCoroutine("targetHit");   
  25.         }
  26.     }
  27.    
  28.     IEnumerator targetHit()
  29.     {
  30.         audio.PlayOneShot(hitSound);
  31.         targetRoot.Play("down");
  32.         beenHit = true;
  33.        
  34.         yield return new WaitForSeconds(resetTime);
  35.        
  36.         audio.PlayOneShot(resetSound);
  37.         targetRoot.Play("up");
  38.         beenHit = false;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement