tpsGunData.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using HQFPSWeapons;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class tpsGunData : MonoBehaviour
  6. {
  7. public string weaponName;
  8. public Transform holding_rightHandPosition;
  9. public Transform aiming_rightHandPosition;
  10. public Transform leftHandPosition;
  11. public Transform headTarget;
  12. [Header("Shooting Properties")]
  13. public GameObject tracerPref;
  14. public GameObject muzzleFlashPref;
  15. public Transform weaponTip;
  16. public Light muzzleLight;
  17. public AudioClip[] shotSfxs;
  18. public float muzzleLightIntensity = 0;
  19. public float muzzleLightMaxIntensity = 2;
  20. private void Update()
  21. {
  22. muzzleLight.intensity = muzzleLightIntensity;
  23. if(muzzleLightIntensity > 0)
  24. {
  25. muzzleLightIntensity -= 0.1f;
  26. }
  27. }
  28. public void triggerMuzzleFlash()
  29. {
  30. Debug.Log("Muzzle flash message recieved!");
  31. muzzleLightIntensity = muzzleLightMaxIntensity;
  32. if (tracerPref != null)
  33. {
  34. PoolableObject tracer = PoolingManager.Instance.GetObject(
  35. tracerPref,
  36. weaponTip.position,
  37. weaponTip.rotation
  38. );
  39. }
  40. if (muzzleFlashPref != null)
  41. {
  42. Quaternion muzzleFlashRot = Quaternion.Euler(new Vector3(
  43. Random.Range(0, 180),
  44. Random.Range(0, 180),
  45. Random.Range(0, 180)));
  46. PoolableObject muzzleFlash = PoolingManager.Instance.GetObject(
  47. muzzleFlashPref,
  48. weaponTip.position,
  49. muzzleFlashRot
  50. );
  51. }
  52. GetComponentInParent<AudioSource>().PlayOneShot(shotSfxs[Random.Range(0,shotSfxs.Length)]);
  53. // foreach (GameObject go in muzzleFlash)
  54. // {
  55. // go.SetActive(true);
  56. // }
  57. // StartCoroutine(disableMuzzleFlashAfterTime(2));
  58. }
  59. IEnumerator disableMuzzleFlashAfterTime(float timeInSeconds)
  60. {
  61. yield return new WaitForSeconds(timeInSeconds);
  62. // foreach (GameObject go in muzzleFlash)
  63. // {
  64. // go.SetActive(false);
  65. // }
  66. }
  67. }