GlobalGameJame/Assets/Scripts/WeaponManager.cs

47 lines
1.2 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-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 05:04:53 +00:00
if (particleShoot != null)
{
GameObject shoot = Instantiate(particleShoot, spawnShoot.transform.position, spawnShoot.transform.rotation);
Destroy(shoot, 0.3f);
}
2020-01-31 23:53:03 +00:00
}
2020-02-01 05:04:53 +00:00
else if (weaponType == WeaponType.Meele)
{
2020-01-31 23:53:03 +00:00
2020-02-01 05:04:53 +00:00
}
fireTime = fireRate + Time.time;
2020-01-31 23:53:03 +00:00
}
}
}