added fire animation and fire rate

This commit is contained in:
juliuse98
2021-11-06 17:07:06 +01:00
parent 4fc928f530
commit 360ceb55f3
8 changed files with 217 additions and 189 deletions

View File

@@ -8,6 +8,14 @@ public class Shoot : NetworkBehaviour
[SerializeField] GameObject muzzle;
[SerializeField] ShootAnimation shootAnim;
[SerializeField] float fireRate;
private void Start()
{
if (isLocalPlayer)
{
shootAnim.OnSwitchWeapon(fireRate);
}
}
private void Update()
{
if (isLocalPlayer)
@@ -28,7 +36,7 @@ public class Shoot : NetworkBehaviour
GameObject dedplayer;
RaycastHit hit;
shootAnim.StartShootAnimation(60f/fireRate);
shootAnimation();
if (Physics.Raycast(muzzle.transform.position, muzzle.transform.forward, out hit))
{
@@ -43,9 +51,9 @@ public class Shoot : NetworkBehaviour
[Client]
// This code will be executed on the Client.
void RpcOnFire()
void shootAnimation()
{
shootAnim.StartShootAnimation(fireRate);
}
}

View File

@@ -6,19 +6,17 @@ public class ShootAnimation : MonoBehaviour
{
private Animator anim;
[SerializeField]private GameObject gun;
void Start()
{
anim = gun.GetComponent<Animator>();
}
void OnSwitchWeapon(GameObject newGun)
public void OnSwitchWeapon(float fireRate)
{
gun = newGun;
//gun = newGun;
anim = gun.GetComponent<Animator>();
anim.SetFloat("ShootSpeed",1f/(60f/fireRate));
}
public void StartShootAnimation(float timeInSeconds)
{
anim.PlayInFixedTime("Shoot", 0, timeInSeconds);
Debug.Log(anim.GetFloat("ShootSpeed"));
anim.Play("Shoot");
}
// Update is called once per frame
void Update()