Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- [RequireComponent (typeof(AudioSource))]
- public class TargetCollision : MonoBehaviour
- {
- bool beenHit = false;
- Animation targetRoot;
- public AudioClip hitSound;
- public AudioClip resetSound;
- public float resetTime = 3.0f;
- // Use this for initialization
- void Start ()
- {
- targetRoot = transform.parent.transform.parent.animation;
- }
- void OnCollsionEnter(Collision theObject)
- {
- if(beenHit == false && theObject.gameObject.name == "coconut")
- {
- StartCoroutine("targetHit");
- }
- }
- IEnumerator targetHit()
- {
- audio.PlayOneShot(hitSound);
- targetRoot.Play("down");
- beenHit = true;
- yield return new WaitForSeconds(resetTime);
- audio.PlayOneShot(resetSound);
- targetRoot.Play("up");
- beenHit = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement