On trigger enter help
Now i know people are not great at answering questions... but may as well ask anyway...
With the on trigger enter function... is it possible to have it only check for collision detection when a bool is active?
Answer by Codelyy · Jan 04, 2017 at 12:49 AM
Just use a if statement within the OnTriggerEnter function.
void OnTriggerEnter2D(Collider2D target)
{
if(bool)
{
}
}
or you could have a function that disables and enables the OnTrigger variable for the collider when a bool is true or false.
yeah the issue i had was not using bools inside... the on trigger... but that it only runs the code inside of it once... what im trying to do is have it detect collision with a enemy... but only do damage if the "IsAttacking" bool is active....but because it only runs once then thats not possible
You need to reset the bool back to false once it's ran the code within the if statement else the "IsAttacking" bool is always going to be true and so it's only going to run the code once.
Your answer
![](https://koobas.hobune.stream/wayback/20220612104016im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Lose Health when GameObject enters collider? (OnTriggerEnter) 2 Answers
NullReferenceException: Object reference not set to an instance of an object 0 Answers
How to disable OnTriggerEnter on one script? 1 Answer
trying to get a door to open when two trigger volumes are activated,Regarding an OnTriggerEnter 0 Answers