59 lines
1.4 KiB
C#
59 lines
1.4 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 bool hit = false;
|
|
|
|
// 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)
|
|
{
|
|
GameObject shoot = Instantiate(particleShoot, spawnShoot.transform.position, spawnShoot.transform.rotation);
|
|
Destroy(shoot, 0.3f);
|
|
}
|
|
}
|
|
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;
|
|
}
|
|
}
|