Advertisement
Guest User

Untitled

a guest
Nov 27th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4.  
  5. namespace Chapter1
  6. {
  7.  
  8.  
  9. public class GrenadeScript : MonoBehaviour {
  10.  
  11. public GameObject explosion;
  12. private bool hasCollided = false;
  13. private Transform myTransform;
  14. AudioSource audio;
  15.  
  16. void Start()
  17. {
  18. SetInitialReferences ();
  19. }
  20.  
  21. // Update is called once per frame
  22. void Update ()
  23. {
  24. if(hasCollided)
  25. {
  26. Destroy (gameObject, 2);
  27.  
  28. }
  29. }
  30.  
  31. void SetInitialReferences()
  32. {
  33. audio = GetComponent<AudioSource>();
  34. myTransform = transform;
  35. }
  36.  
  37. void OnCollisionEnter(Collision collision)
  38. {
  39. hasCollided = true;
  40.  
  41. if(collision.relativeVelocity.magnitude > 2)
  42. {
  43. audio.Play();
  44. }
  45. }
  46.  
  47. void OnDestroy()
  48. {
  49. Instantiate (explosion, myTransform.TransformPoint (0, 0, 0), myTransform.rotation);
  50. }
  51.  
  52.  
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement