SimpleShootingScript.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using UnityEngine;
  2. using System.Collections;
  3. public class SimpleShootingScript : MonoBehaviour
  4. {
  5. public int m_ShootSpeed = 15;
  6. private float mLightOffTime;
  7. public ParticleSystem[] m_VelocityShootParticles;
  8. public ParticleSystem[] m_OtherParticles;
  9. public Light m_ShootLight;
  10. private bool ShootOn;
  11. public GameObject ShootFX;
  12. public Transform m_ShootSound;
  13. void Start()
  14. {
  15. foreach (ParticleSystem i in m_VelocityShootParticles)
  16. {
  17. i.GetComponent<ParticleSystem>().emissionRate = m_ShootSpeed;
  18. }
  19. }
  20. void Update()
  21. {
  22. if (Input.GetButton("Fire1"))
  23. {
  24. //ShootFX.SetActive(true);
  25. ShootNow();
  26. foreach (ParticleSystem i in m_VelocityShootParticles)
  27. {
  28. i.GetComponent<ParticleSystem>().enableEmission = true;
  29. }
  30. foreach (ParticleSystem i in m_OtherParticles)
  31. {
  32. i.GetComponent<ParticleSystem>().enableEmission = true;
  33. }
  34. }
  35. else
  36. {
  37. //ShootFX.SetActive(false);
  38. foreach (ParticleSystem i in m_VelocityShootParticles)
  39. {
  40. i.GetComponent<ParticleSystem>().enableEmission = false;
  41. }
  42. foreach (ParticleSystem i in m_OtherParticles)
  43. {
  44. i.GetComponent<ParticleSystem>().enableEmission = false;
  45. }
  46. }
  47. }
  48. public void ShootNow()
  49. {
  50. if (mLightOffTime < Time.time)
  51. {
  52. Instantiate(m_ShootSound, ShootFX.transform.position,ShootFX.transform.rotation);
  53. m_ShootLight.enabled = !m_ShootLight.enabled;
  54. mLightOffTime = Time.time + 1.0f/ (m_ShootSpeed * 2);
  55. }
  56. }
  57. }