Hey there, I’m getting really irritated by this problem :s. I have an animation that I need to play to switch weapons, but the animation won’t play unless I am holding down the button? Even when using GetButtonDown it only plays it for half a second then stops because the button has already been pressed.
The following code is what I have so far,
void FixedUpdate()
{
if (Input.GetButtonDown("Swap"))
{
WeaponSwitch();
}
}
protected virtual void WeaponSwitch()
{
if (weaponSwitching)
return;
weaponSwitching = true;
weaponSwitchTime = weaponAnimationHolder.animation["SniperToSMG"].length;
weaponAnimationHolder.animation["SniperToSMG"].speed = weaponSwitchTime;
weaponAnimationHolder.animation.Play("SniperToSMG", PlayMode.StopAll);
StartCoroutine(waitFor(weaponSwitchTime));
weaponSwitching = false;
}
IEnumerator waitFor(float waitTime)
{
yield return new WaitForSeconds(waitTime);
}
Could somebody please tell me how to fix this? All I want is my animation “SniperToSMG” to play once without the need to hold down a key.