the script is about animating an object if the collider is on trigger and the key “e” pressed, but it doesn’t work when I add the Input.GetKey… , I think that it’s because it’s not inside the void Update, but I have tried every single thing. (if the input is not set inside the condition the animation works)
private void OnTriggerEnter(Collider _collider)
{
if ((_collider.gameObject.tag == “martillo”) && (Input.GetKeyDown(“e”)))
{
anim.SetTrigger(“cajaT”);
}
}
OnTriggerEnter only returns true once when the player enters the trigger, what I would do is set the animation in OnTriggerEnter and put the check for the input in Update with a bool like this:
private bool isPlaying;
void Update()
{
if(isPlaying && Input.GetButtonDown("Play Animation"))
{
anim.SetTrigger("cajaT");
}
}
void OnTriggerEnter(Collider col)
{
if(col.gameObject.tag == "martillo")
{
isPlaying = true;
}
}
void OnTriggerExit()
{
isPlaying = false;
}
I have used “Input.GetButtonDown()” instead of “Input.GetKeyDown()” because once you’ve set the input tag up you can change the key without having to go back and change the code
Hope this helps
-Joshmond
1 Like
-Joshmond[/QUOTE]
Thank you sooo much, I had been days trying to fix this, I used getkey instead of GetButtonDown, it wasnt working for I don’t know what reason.
It is better to use if (col.CompareTag("martillo"))
as it does not generate any garbage.
1 Like