- Home /
isTrigger not working
So I want this script to turn a door into a trigger so the player can go through it, then become a non-trigger when another door is opened, but the "().isTrigger = true;" won't work
if (isYellow == true)
{
foreach(GameObject Thingy in YellowDoors)
{
Thingy.GetComponent<Renderer>().sharedMaterial.color = new Color(1, 1, 0, 0.25f);
Thingy.GetComponent<Collider>().isTrigger = true;
}
}
The line up the isTrigger line works, meaning that the foreach function is working, just not for the trigger.
Answer by gonzalitosk8 · Feb 09, 2020 at 11:06 PM
Do you have a collider? a common mistake is to find the collider in the parent object, and it does not detect it ... try with .
anywhere, post a photo!
I have both a collider and a rigidbody, it used to work until I have been using the foreach loop.
try: for(int i = 0; i < YellowDoors.Lengt; i++){ YellowDoors[i].gamobject.GetComponent().IsTrigger = true; } using box collider? search , or $$anonymous$$eshCollider, etc..
So I have done the loop you have mentioned and it didn't work, which is why I switched to the foreach. I then decided to rebuild my game (it is my first game and everything was trash making it confusing and broken). Now it doesn't work. Also, I don't think that the foreach loop would break it as it worked it the game beforehand (with some bugs though).
Your answer
Follow this Question
Related Questions
Trigger is not detecting Player. (2D) 1 Answer
Where to attach a script 1 Answer
Problem triggering using colliders 1 Answer
Can't click gameobject when over another trigger? 1 Answer
2D Platformer - Picking Up Items & Storing Them C# 0 Answers