how to change a texture on instantiated prefab?
Please bear with me as I have started learning about coding only two months ago.
I have one script that randomly assigns a graffiti_material to a wall_prefab as they spawn.
In another script as the player interacts with the wall (after 3 hits), it deletes the grafiti and it replaces it with the another material (onHIt material). However, there is one particular grafiti (material name "G_7") that, once interacted with (3 hits), I don't want to change to "onHit" material, but I want to replace it with another graffiti material, named G_77.
if (hitCount == 3 )
{
transform.GetComponent<Renderer>().material = onHit;**
UIManager.instance.moneyEarned++;
UIManager.instance.UpdateScoreUI();
}
So, my question is: how do I find the prefab instance once it is randomly created with the G_7 material and replace only that material with G_77 while the rest continues to use a generic "onHit" material?
I've managed to code the variant where all the graffiti are replaced with the G_77.
if (hitCount ==3 && GameObject.Find("Grafit").GetComponent<Renderer>().material.name == "G_7 (Instance)")
{
transform.GetComponent<Renderer>().material = G_77;
UIManager.instance.moneyEarned++;
UIManager.instance.UpdateScoreUI();
}
but I am unable to figure out how do I tell the code to replace only G_7 with G_77. also, above code