- Home /
Question by
panim0_unity · Feb 23, 2019 at 03:44 PM ·
meshmaterialplayergetcomponentswitch
Change material of an object for all the scenes
This code is able to change this object's material but this sphere is my player object so i want this to be changed for all the scenes until user wants to change it to another one again.
public static GameObject sphere;
public Material[] material;
Renderer rend;
void Start()
{
rend = GetComponent<Renderer>();
rend.enabled = true;
rend.sharedMaterial = material[0];
}
public void choose() {
sphere = GameObject.Find("Sphere");
sphere.GetComponent<Renderer>().material = material[1];
}
Comment
Still Trying
Public static GameObject[] objs;
public $$anonymous$$aterial[] material;
void Start()
{
}
public void choose() {
objs = GameObject.FindGameObjectsWithTag("Spheretag");
foreach (GameObject obj in objs) {
if (obj.name == "Sphere")
{
obj.transform.GetComponent<Renderer>().material = material[1];
}
DontDestroyOnLoad(obj);
}
}
Your answer
Follow this Question
Related Questions
How to switch texture of several 3D objects on GUI buttons click? 1 Answer
Assign a mesh and material to an empty gameobject (JS) 0 Answers
Is it possible to change Shader/Material when animation is played ? 0 Answers
Do I need to manually destroy material/model instances that are lazily copied? 2 Answers
How to highlight only one face of a Cube from script? 0 Answers