- Home /
Question by
NotARealPerson1 · Aug 03, 2021 at 09:13 AM ·
c#fpsshootingvisual studioweapons
Gun Shooting Animation Won't Play
Here's the code
public class GunScript : MonoBehaviour
{
[SerializeField] float Damage = 10f;
[SerializeField] float range = 100f;
[SerializeField] Camera Cam;
[SerializeField] Animator WeaponAnimator;
[SerializeField] AudioSource ShootSource;
[SerializeField] AudioClip ShootSound;
[SerializeField] ParticleSystem MuzzleFlash;
[SerializeField] bool IsAutomatic;
bool isfiring = false;
[SerializeField] string ShootAnimation;
[SerializeField] string IdleAnimation;
void Update()
{
WeaponAnimator.Play(IdleAnimation);
if (Input.GetMouseButtonDown(0))
{
Shoot();
}
}
void Shoot()
{
RaycastHit Hit;
if (Physics.Raycast(Cam.transform.position, Cam.transform.forward, out Hit, range))
{
Debug.Log(Hit.transform.name);
}
ShootSource.PlayOneShot(ShootSound);
MuzzleFlash.Play();
WeaponAnimator.Play(ShootAnimation);
}
}
I have tried putting WeaponAnimator.Play(IdleAnimation) under Void Start and it does, but if I do that, then it screws up the weapon switch code by only playing the "Idle Animations" once. I also do not have any of the idle animations on loop.
Comment
Your answer
Follow this Question
Related Questions
Reload Ammo is not working 0 Answers
Multiple Cars not working 1 Answer
shooting multiple enemies using raycast 2 Answers
Reload Ammo is not working 1 Answer
Distribute terrain in zones 3 Answers