- Home /
Change multiple object layers
Hey Gang, I am trying to change some of my object layers to ignoreRaycast when the weapon menu is active and this is the code I am using
Turrets = GameObject.FindObjectsWithTag("PlayerObject");
for (var OtherTurrets : GameObject in Turrets)
{
if(weaponMenuActive)
{
Turrets.layer = 2;
}else
{
Turrets.layer = 0;
}
}
This is where it gets weird. It works if I happen to click on the object lowest in the scene tree that instantiates the weapon menu, so all of my turrets change to IgnoreRaycast but if I choose any other it doesn't work.
They all have the same script, they're all tagged and the all store in the Array Turrets..
What is going on?
Your answer
![](https://koobas.hobune.stream/wayback/20220613094857im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Return Objects hit by raycast, check against a array of all objects? 1 Answer
How to create User layer that acts like the "Ignore Raycast" layer? 1 Answer
ignore raycast layers problem 1 Answer
Raycast that ignores object with certain tags? 2 Answers
Modifying the HeadLook Controller in C# 2 Answers