Hello, im kinda noob at this stage at programming, my problem is that i want to put all the gameobjects (walls, big gameobjects, etc.), that get hit by a raycast going from my camera to my character, and make them transparent.
*the transparent thing is working fine, the problem is that if there are 2 objects between my camera and my character, only one of them will return to normal if i move around, while the other one will stay transparent. So i thought maybe adding them to a list would work better, so i can then go trough the list and for each gameobject on that list, set it back to normal after the raycast isnt hitting those gameobjects.
You say the transparency is working fine, then that means you’re setting both of them transparent right? So why aren’t you doing the same thing, just opposite on the next frame?
Loop through the hit array before doing the raycast and set them back to visible, then you do your new raycast, which gives you a new list of hit objects and set those to invisible.
Though if you want to optimize it a bit more, you could make a Material[ ] mats; array, and when you do your raycast, you store all the hit object’s materials into this array, that way on the next update, before you do the raycast again, you can loop through these materials and set them back, avoiding some costly GetComponent calls.