F3DFlameThrower.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using UnityEngine;
  2. using System.Collections;
  3. public class F3DFlameThrower : MonoBehaviour
  4. {
  5. public Light pLight; // Attached point light
  6. public ParticleSystem heat; // Heat particles
  7. int lightState; // Point light state flag (fading in or out)
  8. bool despawn; // Despawn state flag
  9. ParticleSystem ps;
  10. void Start()
  11. {
  12. ps = GetComponent<ParticleSystem>();
  13. }
  14. // OnSpawned called by pool manager
  15. void OnSpawned()
  16. {
  17. despawn = false;
  18. F3DAudioController.instance.FlameGunLoop(transform.position, transform);
  19. lightState = 1;
  20. pLight.intensity = 0f;
  21. }
  22. // OnDespawned called by pool manager
  23. void OnDespawned()
  24. {
  25. }
  26. // Despawn game object
  27. void OnDespawn()
  28. {
  29. F3DPool.instance.Despawn(transform);
  30. }
  31. void Update()
  32. {
  33. // Despawn on mouse
  34. if (Input.GetMouseButtonUp(0))
  35. {
  36. if (!despawn)
  37. {
  38. // Set despawn flag and add despawn timer allowing particles fading
  39. despawn = true;
  40. F3DTime.time.AddTimer(1f, 1, OnDespawn);
  41. // Stop the particle systems
  42. ps.Stop();
  43. if (heat)
  44. heat.Stop();
  45. // Play
  46. F3DAudioController.instance.FlameGunClose(transform.position);
  47. // Toggle light state
  48. pLight.intensity = 0.6f;
  49. lightState = -1;
  50. }
  51. }
  52. // Fade in point light
  53. if (lightState == 1)
  54. {
  55. pLight.intensity = Mathf.Lerp(pLight.intensity, 0.7f, Time.deltaTime * 10f);
  56. if (pLight.intensity >= 0.5f)
  57. lightState = 0;
  58. }
  59. // Fade out point light
  60. else if (lightState == -1)
  61. {
  62. pLight.intensity = Mathf.Lerp(pLight.intensity, -0.1f, Time.deltaTime * 10f);
  63. if (pLight.intensity <= 0f)
  64. lightState = 0;
  65. }
  66. }
  67. }