- Home /
Input press to play different animation to input hold?
Is this possible? I'm trying to make a button press do a jumping animation and action whilst trying to make a button hold do a sliding animation and action, I feel like there is a simple answer but I can't seem to find anything to do with monitoring how long the button is pressed down for as I know this would make it much easier.
Currently I have it so that it can change but as this code was written by my lecturer I'm not 100% sure I understand what it does. It's a 2D one button game I'm making. Here is my code that is related to my issue, any help appreciated.
private float slideTime = 1.0f;
public float jumpTime = 1.0f;
...
void Update() {
if (Input.GetKey(KeyCode.Space) && Time.time > slideTime) Slide();
}
...
void Jump() {
if(Input.GetButtonDown("Jump") && Time.time < slideTime)
{
audio.PlayOneShot(JumpSound2);
rigidbody2D.AddForce(new Vector2(0, jumpSpeed));
anim.Play("Jumping");
}
}
void Slide()
{
if(Input.GetButtonDown("Jump") && Time.time > slideTime)
{
slideTime = Time.time + jumpTime;
anim.Play("Sliding");
}
}
Comment