- Home /
Changing material of objects by the tag in different scenes
Here's what i want to do. On menu user will click a button and it will change the material on sphere which is the player object in every scene i have. So i tried to make this happen by writing this code but it didnt really do what i wanted to do. it changes only one sphere in one scene where this button displays. after selecting a material you press play button and it load a new scene and in the new scene the sphere doesn't change. each scene has only one sphere with same name and tag.
 public GameObject[] objs;
 public GameObject obj2;
 public Material[] material;
 
 Renderer rend;
 void Start()
 {
     objs = GameObject.FindGameObjectsWithTag("Spheretag");
 }
 public void choose() {
 
     foreach (GameObject obj in objs) {
 
         if (obj.name == "Sphere")
         {
             obj.transform.GetComponent<Renderer>().material = material[1];
         }
 
     }
     UnityEditor.AssetDatabase.SaveAssets();
 
 }
Your answer
 
 
             Follow this Question
Related Questions
Changing two different objects renderer colour 1 Answer
Calling an Audio Source on one game object from a script on another game object..? 1 Answer
Turning off renderer in other game object (C#) 2 Answers
how to use itween with the object attached to other moving object 0 Answers
Material Switching Upon Instantiation. over my head 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                