Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- namespace Chapter1
- {
- public class GrenadeScript : MonoBehaviour {
- public GameObject explosion;
- private bool hasCollided = false;
- private Transform myTransform;
- AudioSource audio;
- void Start()
- {
- SetInitialReferences ();
- }
- // Update is called once per frame
- void Update ()
- {
- if(hasCollided)
- {
- Destroy (gameObject, 2);
- }
- }
- void SetInitialReferences()
- {
- audio = GetComponent<AudioSource>();
- myTransform = transform;
- }
- void OnCollisionEnter(Collision collision)
- {
- hasCollided = true;
- if(collision.relativeVelocity.magnitude > 2)
- {
- audio.Play();
- }
- }
- void OnDestroy()
- {
- Instantiate (explosion, myTransform.TransformPoint (0, 0, 0), myTransform.rotation);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement