Answer the question
In order to leave comments, you need to log in
How to work with list items individually?
The problem is this - I have a certain number of objects (enemies) that become inactive if their health drops below zero, but if on the same active scene I enter a positive amount of health again for them, then the object remains still inactive due to the fact that the code is not works for an inactive object. I decided to use a separate script hanging on the camera, where I created a public list of objects where all my enemies lie, but how to make the script work on a specific enemy from the list, and not on all, since individually the enemies do not become inactive, the code only triggers when all enemies have less than zero health.
My underscript looks like this-
if (health <=0 && Enemy[i].activeInHierarchy)
{
Enemy[i].SetActive(false);
}
else if(health > 0 && Enemy[i].activeInHierarchy == false)
{
Enemy[i].SetActive(true);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question