How to make a material look the same on different levels?

Hey, so I used a script that I can change the material of my sphere on the main menu, but when I load the first level it doesn’t work, it uses the default texture, I tried doing prefabs but that didn’t work. any help?
PM me for my teamviewer details.

Bump

Then you need to call this script in Awake() or Start() so it sets the texture when the scene loads.

This is the script that I attach to the buttons that if they are pressed they will change the material of my sphere

using UnityEngine;
public class SkinSelectorButton : MonoBehaviour {
    // Reference to the sphere object.
    public GameObject sphere;
    // The material that is to be selected.
    public Material skinMaterial;
    private void OnMouseDown() {
        sphere.renderer.sharedMaterial = skinMaterial;
    }
}

what do I need to do?

You could just apply the material you would like it to start with on the sphere in the editor.

I did but it didn’t work on the other sphere on the other level

OK when you load a new scene the old scene and everything in it is destroyed unless you set an object to DontDestoryOnLoad - Unity - Scripting API: Object.DontDestroyOnLoad

Can I send you my teamviewer? it didn’t work.

Not even sure what teamviewer is, so No.

There is another way to do it…
Use a Settings script with a static material variable
Ensure the script settings script uses DontDestroyOnLoad

using UnityEngine;
using System.Collections;

public class Settings : MonoBehaviour {

    static Material material;

    void Awake()
    {
        DontDestroyOnLoad(this.gameObject);
    }

}

Set the variable when you in the OnMouseDown method as well as the sphere.

using UnityEngine;
public class SkinSelectorButton : MonoBehaviour {
    // Reference to the sphere object.
    public GameObject sphere;
    // The material that is to be selected.
    public Material skinMaterial;
    private void OnMouseDown() {
        sphere.renderer.sharedMaterial = skinMaterial;
        Settings.material = skinMaterial; // TADA
    }
}

When the new scene is loaded have a Start() method set the material on the sphere from the settings script.

//*** In a start method in the level
void Start() {
   sphere.renderer.sharedMaterial = Settings.material;
}

It’s a bit more convoluted but should allow you to take the setting into the next level that is loaded and any level after that.

You could also save the selection as a playerprefs, and load it on Start()

Teamviewer is a program that you can remote control my computer so you could help me.

Ah that could be useful if you’re working with a small team you trust, but I personally would not want strangers I meet on a forum controlling my computer.

But if you have any questions I will attempt to help.

No I want you to control MY computer.

No thank you, but I will try to help you with your problem on the forum.

I don’t know where to put all the script you sent me, what object? main camera?

Create an empty game object, rename it to Settings and add the settings script (only needed in your material selection scene).

Update your Button Script.

Create a SetSkin script with the Start method and drop it on the sphere in your levels.

What I need to update in my button script?

?

It’s really complicated the script that you wrote me and I don’t know what to do… is there any way you could help me?

Bump