|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class Weapon : MonoBehaviour
|
|
|
|
{
|
|
|
|
[SerializeField] private int maxAmmo;
|
|
|
|
[SerializeField] private float shootSpeed;
|
|
|
|
[SerializeField] private int damage;
|
|
|
|
[SerializeField] private bool fullAuto;
|
|
|
|
[SerializeField] private float shootPointHeight;
|
|
|
|
[SerializeField] private GameObject Bullet;
|
|
|
|
private int Ammo;
|
|
|
|
private bool shootDone;
|
|
|
|
private float Wait;
|
|
|
|
private Transform shootPoint;
|
|
|
|
private SpriteRenderer SR;
|
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
Ammo = maxAmmo;
|
|
|
|
shootPoint = transform.GetChild(0);
|
|
|
|
SR = transform.GetComponent<SpriteRenderer>();
|
|
|
|
}
|
|
|
|
public void shoot()
|
|
|
|
{
|
|
|
|
if(Ammo == 0 || Wait > 0 || shootDone && !fullAuto)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(!fullAuto)
|
|
|
|
{
|
|
|
|
shootDone = true;
|
|
|
|
}
|
|
|
|
Wait += shootSpeed;
|
|
|
|
GameObject bullet = GameObject.Instantiate(Bullet, shootPoint.position, transform.rotation);
|
|
|
|
bullet.GetComponent<Bullet>().setDmg = damage;
|
|
|
|
bullet.GetComponent<Bullet>().OwnTag = transform.tag;
|
|
|
|
}
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
Wait -= Time.deltaTime;
|
|
|
|
Wait = Mathf.Clamp(Wait, 0, shootSpeed);
|
|
|
|
if(Wait == 0)
|
|
|
|
{
|
|
|
|
shootDone = false;
|
|
|
|
}
|
|
|
|
if(SR.flipY)
|
|
|
|
{
|
|
|
|
shootPoint.localPosition = new Vector3(shootPoint.localPosition.x, -shootPointHeight, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shootPoint.localPosition = new Vector3(shootPoint.localPosition.x, shootPointHeight, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|