I’m new at this so try to explain as if I was a stillborn child.
So I manage to instantiate some prefab clones and now I would like to be able to change the color
of a component inside one of the clones. How do I go about doing that?
I have 4 clones, each prefab contains 5 basic images with their own names.
Say I want to change image3 color to Red in clone 4?
public void Create ()
{
word = new List ();
for (int i = 0; i < numberOfLetters; i++)
{
letter = Instantiate (letter, new Vector2(i*spawnXposition,0), transform.rotation) as GameObject;
letter.transform.SetParent (GameObject.FindGameObjectWithTag (“Canvas”).transform, false);
word.Add(letter);
letter.name = “letter”+i;
}
}
Sorry Johne5, I’ve done extensive googling on the matter but since I don’t know where to begin everything looks like heiroglyps to me. Could you please elaborate what I need to do?
Maybe the problem is that 2d images doesnt have the renderer as a component?
For this thing I’m using unity 2D and my prefabs only contains 5 different 2d images. Trying to change color to one of the images but I can’t find a reference to it once they’re spawned onto my canvas.
Trying to do something like this? No luck.
word[0].GetComponent ().color = new Color32 (255, 0, 0, 255);
if it’s 5 sub objects then you need to do a GetCompontsInChildern()
this will return an array. you then loop though the array and change the image color.
fuck me! I don’t understand any of this. I get what you’re saying but it returns an array…return to what. I’m days into coding so I don’t get it. hate that it takes time to learn new things, I want it in my brain now.
I think I’ve understood that when I creaded a 2d image and made that into a prefab and instantiate that…
it had no Renderer component because that is probably for a 3d object or something.
So now I tried creating a 2d Sprite instead using SpriteRenderer but that turned bad as well.
So the other guy said that I’m probably not trying to access the color component of the correct object…
so the Correct object i.e the image…inside the Sprite…is the one…and I should find that via your
GetComponentsInChildren() but how…
I need some kinda… blah = GetComponentsInChildren(); or something, I don’t get the return thing.
ok, so you’re a complete noob with coding, sorry I though you some exp.
I was just giving you some idea’s.
The best thing you can do is to post the complete code you’re using. and a screen shot of the prefab after it gets spawned. So i can what elements you have added to the prefab.
This will help me understand you’re setup and get you an answer.