- Home /
Animation doesn't play on Input
I've written a little script to open a door when the player is inside of a box collider and hits the Interact button (I've set it up to be 'E' in the input manager)(I've also tried this same code using the 'E' Keycode directly). It works (door opens) when I comment out the test for the interaction button (player just steps into the collider) but doesn't seem to work when I add the extra if statement if (Input.GetButtonDown("Interact"))
.
Any idea what I could be doing wrong?
void OnTriggerEnter(Collider other) {
if (other.tag == "Player")
{
canvas.enabled = true;
if (Input.GetButtonDown("Interact"))
{
animator.SetBool("open", true);
}
}
Side note: Anyone else excited for Ludum Dare 40 tonight?!
Cheers!
Answer by Hiyek · Dec 01, 2017 at 10:29 PM
https://www.twitch.tv/honestdangames answered my question on a stream (by the way, check out his stream, he's an awesome guy and a fellow Unity developer! The Ludum Dare site links to his stream quite often!) and sorry if the devs don't condone linking, but he did answer my question, for which I'm very grateful:
The problem was void OnTriggerEnter(Collider other)
the compiler was looking for input only on the very first frame of entering the collider.
The solution was to change it to void OnTriggerStay(Collider other)
.
Your answer
Follow this Question
Related Questions
GetButton will only play animation when held down 2 Answers
Character Hit Animation play endlessly 2 Answers
Change Idle/Walk player animation permanently on trigger colliders 1 Answer
Collide with object trigger - why animation only occurs on first encounter with trigger 1 Answer
How to have a collider inactive only during attack animation and not during 'charging' animation? 1 Answer