GlobalGameJame/Assets/Scripts/WeaponManager.cs

66 lines
1.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeaponManager : MonoBehaviour
{
public enum WeaponType { None, Shoot, Meele };
public WeaponType weaponType = WeaponType.None;
public float weaponRange = 1;
public GameObject spawnShoot;
public GameObject particleShoot;
public float damage = 0;
public float fireRate = 0.5f;
private float fireTime;
public Animator animator;
public PlayerManager player;
public bool hit = false;
public AudioSource audioSource = new AudioSource();
public AudioClip shootSound;
// Start is called before the first frame update
void Start()
{
fireTime = fireRate;
}
// Update is called once per frame
void Update()
{
WeaponAttack();
}
public void WeaponAttack()
{
if (Input.GetMouseButtonDown(0) && fireTime <= Time.time) {
if (weaponType == WeaponType.Shoot)
{
if (particleShoot != null && player.ammo > 1)
{
GameObject shoot = Instantiate(particleShoot, spawnShoot.transform.position, spawnShoot.transform.rotation);
audioSource.PlayOneShot(shootSound);
player.ammo -= 2;
Destroy(shoot, 0.3f);
fireTime = fireRate + Time.time;
}
}
else if (weaponType == WeaponType.Meele)
{
animator.ResetTrigger("Hit");
animator.SetTrigger("Hit");
fireTime = fireRate + Time.time;
}
}
}
void Hit_Enemy_Start()
{
hit = true;
}
void Hit_Enemy_End()
{
hit = false;
}
}