using System.Runtime.InteropServices; using StarterAssets; using UnityEngine; public class Weapon : MonoBehaviour { [SerializeField] int weaponDamage = 10; [SerializeField] ParticleSystem muzzleFlash; [SerializeField] GameObject hitVFXPrefab; Animator animator; StarterAssetsInputs starterAssetsInputs; const string SHOOT_STRING = "Shoot"; void Awake() { starterAssetsInputs = GetComponentInParent(); animator = GetComponentInParent(); } // Update is called once per frame void Update() { HandleShoot(); } void HandleShoot() { if (!starterAssetsInputs.shoot) return; muzzleFlash.Play(); animator.Play(SHOOT_STRING, 0, 0f); starterAssetsInputs.ShootInput(false); RaycastHit hit; if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, Mathf.Infinity)) { Instantiate(hitVFXPrefab, hit.point, Quaternion.identity); EnemyHealth enemyHealth = hit.transform.GetComponent(); enemyHealth?.TakeDamage(weaponDamage); } } }