Advertisement
KorolevDmitry123

Untitled

Jul 27th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class BulletSound : MonoBehaviour {
  5. public AudioSource source;
  6. private GameObject bullet;
  7. public AudioClip ShootE;
  8. public AudioClip ShootP;
  9. public AudioClip ShootM;
  10. public AudioClip ShootG;
  11. public AudioClip ShootV;
  12. public AudioClip ShootR;
  13. public bool e;
  14. public GameObject _bullet;
  15. void Start()
  16. {
  17. bullet = (GameObject)this.gameObject;
  18. source = GetComponent<AudioSource>();
  19. source.loop = false;
  20. }
  21. void OnCollisionEnter(Collider collider)
  22. {
  23. switch (collider.tag)
  24. {
  25. case "Ring":
  26. bullet.GetComponent<AudioSource>().PlayOneShot(ShootR);
  27. _bullet.gameObject.SetActive(false);
  28. Debug.Log("R");
  29. break;
  30. case "Metal":
  31. bullet.GetComponent<AudioSource>().PlayOneShot(ShootM);
  32. _bullet.gameObject.SetActive(false);
  33. Debug.Log("M");
  34. break;
  35. case "Plastic":
  36. bullet.GetComponent<AudioSource>().PlayOneShot(ShootP);
  37. _bullet.gameObject.SetActive(false);
  38. Debug.Log("P");
  39. break;
  40. case "Glass":
  41. bullet.GetComponent<AudioSource>().PlayOneShot(ShootG);
  42. _bullet.gameObject.SetActive(false);
  43. Debug.Log("G");
  44. break;
  45. case "Vidic":
  46. bullet.GetComponent<AudioSource>().PlayOneShot(ShootV);
  47. _bullet.gameObject.SetActive(false);
  48. Debug.Log("V");
  49. break;
  50. }
  51. }
  52. void OnTriggerEnter(Collision collision1)
  53. {
  54. if (collision1.CompareTag("Enemy"))
  55. {
  56. e = true;
  57. }
  58. }
  59. void Update()
  60. {
  61. if (e == true)
  62. {
  63. bullet.GetComponent<AudioSource>().PlayOneShot(ShootE);
  64. _bullet.gameObject.SetActive(false);
  65. Debug.Log("E");
  66. e = false;
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement