Newly Instantiated Prefabs Not Changing Colour
I have a prefab called "Row1". It is a row of three squares. Two of the squares are dark blue, the middle one is light blue.
I have succeeded in turning the dark blue squares to light blue when the light blue square in the middle detects the player object.
Once this happens, the same prefab "Row1" is generated on top of the previous one. However, when the newest "Row1" prefab detects the player, the dark blue squares do not turn light blue.
The logic of my script (in natural English):
When the light blue square detects the player, find the SpriteRenderer of the first dark blue square and the second dark blue square (using GameObject.Find("darkSquare1").GetComponent() etc etc, and set their colours to light blue. Sorry for being so vague, I'm crap at explaining myself. Any help would be greatly appreciated :) Farid
If you are in fact using "GameObject.Find("darkSquare1").GetComponent() etc etc" and there are multiple "darkSqaure1"s in the scene, then you are probably only finding the first instantiated instance of "darkSquare1". You will need to do something like tag all the blue squares something and use GameObject.FindGameObjectsWithTag() and then iterate through the returned array, changing each one from dark blue to light blue. See the reference page here.
Hope this helps.
If you already have a 'row' prefab with those 3 objects and all rows behave the same, it would probably be easiest to attach a script to the middle square with 2 public gameobject variables in it and drag references to the left and right square to those. Now all rows know which are their 'side squares'. Since you are already able to tell which middle square the player hits, it shouldn't be hard to tell that middle square change the color of its own side squares
Answer by fazraz · Dec 09, 2015 at 04:25 PM
Thankyou @ZefanS and @NoseKills for your replies. I sorted the problem by serializing a public GameObject space for the dark blue squares and manually dragging them into the correct spaces in the editor. Then I saved this as the prefab.
I appreciate your help!