So I have an FPS controller I’m trying to set up, and when I switch from one weapon to another, if I cut off the animations mid weapon draw, and then switch back, the weapon goes through the weapon draw animation, but then the idle state snaps down to where it was originally cut off from.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeaponManager : MonoBehaviour
{
[SerializeField]
private Weapons[] weapons;
private int current_Weapon_Index;
private void Start()
{
current_Weapon_Index = 0;
weapons[current_Weapon_Index].gameObject.SetActive(true);
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
TurnOnSelectedWeapon(0);
}
if (Input.GetKeyDown(KeyCode.Alpha2))
{
TurnOnSelectedWeapon(1);
}
if (Input.GetKeyDown(KeyCode.Alpha3))
{
TurnOnSelectedWeapon(2);
}
if (Input.GetKeyDown(KeyCode.Alpha4))
{
TurnOnSelectedWeapon(3);
}
}
void TurnOnSelectedWeapon(int weaponIndex)
{
weapons[current_Weapon_Index].gameObject.SetActive(false);
weapons[weaponIndex].gameObject.SetActive(true);
if (weapons[weaponIndex].drawnSound != null)
{
weapons[weaponIndex].drawnSound.Play();
}
current_Weapon_Index = weaponIndex;
}
public Weapons GetCurrentSelectedWeapon()
{
return weapons[current_Weapon_Index];
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum WeaponAim {
NONE, SELF_AIM, AIM
}
public enum WeaponFireType
{
SINGLE,
BURST,
AUTO
}
public enum WeaponBulletType
{
HITSCAN,
PROJECTILE,
NONE,
}
public class Weapons : MonoBehaviour
{
public Animator anim;
[SerializeField]
private GameObject muzzleFlash;
[SerializeField]
public AudioSource shootSound, reloadSound, drawnSound;
public WeaponFireType fireType;
public WeaponAim weaponAim;
public WeaponBulletType bulletType;
public GameObject attack_point;
void Awake()
{
anim = GetComponent<Animator>();
}
public void ShootAnimation()
{
anim.SetTrigger("Shoot");
Instantiate(muzzleFlash);
}
public void Aim(bool canAim)
{
anim.SetBool("isAiming", canAim);
}
void Turn_On_MuzzleFlash()
{
muzzleFlash.SetActive(true);
}
void Turn_Off_MuzzleFlash()
{
muzzleFlash.SetActive(false);
}
void Play_Shoot_Sound()
{
shootSound.Play();
}
void Play_Reload_Sound()
{
reloadSound.Play();
}
void Turn_On_AttackPoint()
{
attack_point.SetActive(true);
}
void Turn_Off_AttackPoint()
{
if (attack_point.activeInHierarchy)
{
attack_point.SetActive(false);
}
}
}
I’ve been stuck on this for a few days and read multiple other threads with various suggestions but I can’t get any of them to work.