mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 20:52:10 +01:00
Weapons start_2
+ added shooting animation + added idle animation
This commit is contained in:
@@ -6,7 +6,7 @@ public class Weapon : MonoBehaviour
|
||||
{
|
||||
[SerializeField] bool active = false;
|
||||
[SerializeField] float damage = 0;
|
||||
[SerializeField] int firerate = 0;
|
||||
[SerializeField] float firerate = 0;
|
||||
[SerializeField] float recoilStrength = 0;
|
||||
[SerializeField] int currentAmmunition = 0;
|
||||
[SerializeField] int totalAmmunition = 0;
|
||||
@@ -14,11 +14,16 @@ public class Weapon : MonoBehaviour
|
||||
[SerializeField] ParticleSystem smoke;
|
||||
[SerializeField] GameObject bulletExit;
|
||||
[SerializeField] GameObject camera;
|
||||
|
||||
|
||||
public bool Active { get => active; set => active = value; }
|
||||
|
||||
private bool allowShoot = true, isShooting = false;
|
||||
Animator anim;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
anim = GetComponent<Animator>();
|
||||
|
||||
if (Physics.Raycast(camera.transform.position, camera.transform.forward, out RaycastHit hit))
|
||||
{
|
||||
transform.rotation = Quaternion.Euler(0f, hit.point.y, 0f);
|
||||
@@ -26,15 +31,29 @@ public class Weapon : MonoBehaviour
|
||||
}
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (Input.GetButton("Fire1"))
|
||||
if (Input.GetButton("Fire") && allowShoot && currentAmmunition > 0)
|
||||
{
|
||||
anim.Play("USP");
|
||||
isShooting = true;
|
||||
StartCoroutine(fireRate());
|
||||
fire();
|
||||
currentAmmunition--;
|
||||
}
|
||||
else
|
||||
{
|
||||
isShooting = false;
|
||||
}
|
||||
if (Input.GetButton("Reload"))
|
||||
{
|
||||
currentAmmunition = totalAmmunition;
|
||||
}
|
||||
|
||||
}
|
||||
private void fire()
|
||||
{
|
||||
allowShoot = false;
|
||||
flash.Play();
|
||||
smoke.Play();
|
||||
//smoke.Play();
|
||||
RaycastHit hit;
|
||||
|
||||
if(Physics.Raycast(bulletExit.transform.position,bulletExit.transform.forward, out hit))
|
||||
@@ -46,5 +65,14 @@ public class Weapon : MonoBehaviour
|
||||
}
|
||||
Instantiate(bulletImpact, hit.point, Quaternion.LookRotation(hit.normal));*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
IEnumerator fireRate()
|
||||
{
|
||||
allowShoot = false;
|
||||
yield return new WaitForSeconds(firerate);
|
||||
allowShoot = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user