- Home /
enable collider when gameobject false
hello , how i use Colliders2D in game when my Gameobjects is SetActive false i have many gameobjects false but i need get tag and Colliders
public List Colliders = new List();
public List GetColliders() { return Colliders; }
void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("G")) { if (!Colliders.Contains(other)) { Colliders.Add(other);
}
}
}
void OnTriggerExit2D(Collider2D other)
{
if (other.CompareTag("G"))
{
Colliders.Remove(other);
}
}
when system check tag , can't found becuase game object false thanks .
What do you mean when you say that the gameobject is false? And which gameobject are you talking about?
i get my answer but i mean to gameobject in hierarchy
Hi!
Well, I would say that this depends on what you are trying to achieve, because if you have disabled GameObject then its collider cannot be detected, so I would suggest you to find workaround depending on your aim.
For example, as I can see you are working in 2D space since you are using Collider2D, so probably the main reason for disabling GameObject is to not render it. You can disable Image or Sprite Renderer ins$$anonymous$$d, it will make it invisible meanwhile other components will stay active. Or if the reason is to not execute attached script then you can disable the script itself, not the GameObject class.
It will be more easier approach.
Your answer
Follow this Question
Related Questions
Zombie won't die 2 Answers
SetActive() not working on child objects 2 Answers
Check if collider is colliding with anything non specific? 1 Answer
!IsActive && !GetRunInEditMode 5 Answers