-1

Hi i am working on a game in which i created a character selection scene in which i show the player some models with different materials now i want those materials to pass onto the gameplay scene without changing the models here is the code in the receiving side the code is almost same on the selection side too. the script i am getting data from is MainMenu script.

public GameObject BabyPajama;
public GameObject BabyDiaper;
public SkinnedMeshRenderer BabyPajamaRenderer;
public int selectedIndex;

void Start()
{
    ReplaceSuit(PlayerPrefs.GetInt("UnlockedSkin"));

    //PajamasTexture = MainMenu.Instance.PajamasTexture;
    //BabyPajamaRenderer = MainMenu.Instance.BabyPajamaRenderer;
    //selectedIndex = MainMenu.Instance.sId;


    
}


void Update()
{

}
public void ReplaceSuit(int index)
{
    selectedIndex = index;
    for (int i = 0; i < 5; i++)
    {
        if (index == 0)
        {

            BabyDiaper.SetActive(true);
            BabyPajama.SetActive(false);
        }
        else
        {
            BabyDiaper.SetActive(false);
            BabyPajama.SetActive(true);
        }

        if (i == index) Hair[i].SetActive(true);
        else Hair[i].SetActive(false);
    }
    BabyPajamaRenderer.materials[1].mainTexture = PajamasTexture[index];
}

}

derHugo
  • 83,094
  • 9
  • 75
  • 115
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Oct 17 '21 at 15:46
  • Please use the correct tags! Note that [`unityscript`](https://stackoverflow.com/tags/unityscript/info) is or better **was** a JavaScript flavor like custom language used in early Unity versions and is long **deprecated** by now! Your code is clearly `c#` ... – derHugo Oct 23 '21 at 09:07

1 Answers1

0

You can create a sort of "ModelHandler" GameObject with a script that holds your material. You then say Unity to not destroy the GameObject when switching scenes.
See: DontDestroyOnLoad

See the example code here:

public class DontDestroy : MonoBehaviour
{
    void Awake()
    {
        DontDestroyOnLoad(gameObject);
    }
}

In the other scene you could search for the "ModelHandler" by its tag with FindGameObjectsWithTag.

Daniel M
  • 746
  • 5
  • 13