Initial commit
This commit is contained in:
39
Assets/Scripts/Weapon.cs
Normal file
39
Assets/Scripts/Weapon.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
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<StarterAssetsInputs>();
|
||||
animator = GetComponentInParent<Animator>();
|
||||
}
|
||||
// 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>();
|
||||
enemyHealth?.TakeDamage(weaponDamage);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user