Here is the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
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.