- Home /
Question by
El_Pau678 · Aug 02, 2017 at 12:25 AM ·
animator controlleranimations3rd person controllercrouch
loop an animation if the button witch activates it is still pressed
I am starting a game and i have a animation manager code that activates an anim when i press a number or (in these case the left control). Well my problem is that when i press left controll the player crouch, and if i stop presing these button, the player gets up again, but when the anim of crouch idle ends the player gets up even if i continue pressing left controll. I have tried to put getkey instead of getkeydown but like these the anim dosn't play because is like all the time startig it.
this is my code:
using UnityEngine;
using System.Collections;
public class player : MonoBehaviour {
public Animator anim;
CharacterController charactercollider;
void Start ()
{
anim = GetComponent<Animator>();
charactercollider = gameObject.GetComponent<CharacterController>();
}
void Update()
{
if (Input.GetKeyDown("1"))
{
anim.Play("standing_idle_02_looking", -1, 0f);
}
if (Input.GetKeyDown("2"))
{
anim.Play("standing_idle_03_examine", -1, 0f);
}
if (Input.GetKeyDown(KeyCode.LeftControl))
{
anim.Play("crouch_idle_01", -1, 0f);
}
else
{
if ((Input.GetKeyUp(KeyCode.LeftControl)))
{
anim.Play("standing_idle_01", -1, 0f);
}
}
}
}
i'm sorry for my eanglish, i'm not very pro that way.
Comment