I have a list of instantiated prefabs. A function is called that loops through them and for each gameobject that is not set to owner==1, its renderer is disabled. This part WORKS. The part that does not work is when I call the function that loops back through them and re-enables the renderer using almost the exact same code, just changing false to true for the renderer setting.
Here is the loop that functions properly:
for (var i = 0; i+1 <= landtiles.Count; i++){
var x : Transform;
x = landtiles*;*
-
if (!(x.GetComponent(tilescript).owner == 1)){* -
x.renderer.enabled = false; * -
}* - }*
Here is the loop that does not: -
for (var i = 0; i+1 <= landtiles.Count; i++){* -
var x : Transform;*
_ x = landtiles*;_
_ x.renderer.enabled = true;_
_ Debug.Log(x.renderer.enabled); _
_ }*_
I tried using the exact same code in loop 2 as in loop 1 but just changing false to true, but that did not work. So instead of limiting myself to just those gameobjects with owner == 1 I had it set renderer.enabled to true for each tile in the list. This also did not have any of the gameobjects display in game.
The kicker is Debug.Log(x.renderer.enabled) returns true. Why is this not rendering in game?
Even stranger, after I execute the second loop setting the renderer back to true, debug.log shows it as set as true, but during play if I switch from Game to Scene view, the tiles that debug.log says should have a mesh renderer component enabled do not.
– violenceI have no idea, your code looks fine. Try doing it a different way anyway: for (var t : Transform in landTiles) { var r : Renderer = t.gameObject.GetComponent.< Renderer >(); r.enabled = true; }
– KiloblarghNegative, this change yields nothing noticeably different. This is killing me, why would debug.log tell me the renderer is enabled but it would not be? I've got to be doing something really stupid but I can't figure out what. All searches on here and google tell me it should be working.
– violenceYou are absolutely right, you've gotten me close. in the script attached to each landtile, I put a debug in the update function broadcasting its renderer.enabled status and youre right, as soon as theyre turned true, they revert right back to false. I believe I have a logic error. You should convert your last comment into an answer. I'll mark it as correct as soon as I figure it out.
– violence