GlobalGameJame/Assets/Scripts/WeaponManager.cs

62 lines
1.6 KiB
C#
Raw Normal View History

2020-01-31 23:53:03 +00:00
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;
2020-02-01 05:04:53 +00:00
public GameObject spawnShoot;
public GameObject particleShoot;
2020-01-31 23:53:03 +00:00
public float damage = 0;
2020-02-01 05:04:53 +00:00
public float fireRate = 0.5f;
private float fireTime;
2020-02-01 17:17:29 +00:00
public Animator animator;
2020-02-01 18:49:53 +00:00
public PlayerManager player;
2020-02-01 17:17:29 +00:00
public bool hit = false;
2020-01-31 23:53:03 +00:00
// Start is called before the first frame update
void Start()
{
2020-02-01 05:04:53 +00:00
fireTime = fireRate;
2020-01-31 23:53:03 +00:00
}
// Update is called once per frame
void Update()
{
2020-02-01 05:04:53 +00:00
WeaponAttack();
2020-01-31 23:53:03 +00:00
}
2020-02-01 05:04:53 +00:00
public void WeaponAttack()
2020-01-31 23:53:03 +00:00
{
2020-02-01 05:04:53 +00:00
if (Input.GetMouseButtonDown(0) && fireTime <= Time.time) {
if (weaponType == WeaponType.Shoot)
2020-01-31 23:53:03 +00:00
{
2020-02-01 18:49:53 +00:00
if (particleShoot != null && player.ammo > 1)
2020-02-01 05:04:53 +00:00
{
GameObject shoot = Instantiate(particleShoot, spawnShoot.transform.position, spawnShoot.transform.rotation);
2020-02-01 18:49:53 +00:00
player.ammo -= 2;
2020-02-01 05:04:53 +00:00
Destroy(shoot, 0.3f);
2020-02-01 18:49:53 +00:00
fireTime = fireRate + Time.time;
2020-02-01 05:04:53 +00:00
}
2020-01-31 23:53:03 +00:00
}
2020-02-01 05:04:53 +00:00
else if (weaponType == WeaponType.Meele)
{
2020-02-01 17:17:29 +00:00
animator.ResetTrigger("Hit");
animator.SetTrigger("Hit");
2020-02-01 18:49:53 +00:00
fireTime = fireRate + Time.time;
2020-02-01 05:04:53 +00:00
}
2020-01-31 23:53:03 +00:00
}
}
2020-02-01 17:17:29 +00:00
void Hit_Enemy_Start()
{
hit = true;
}
void Hit_Enemy_End()
{
hit = false;
}
2020-01-31 23:53:03 +00:00
}