instantiate a cloned prefab in another scene
I change the hat of my character and when i start the game the game manager on the 1 level instantiate the clone of my character but the problem is that instantiated character has no hat equipped its just the default character prefab with no customization. Here is my character selection script: { public GameObject[] characters; public int selectedCharacter = 0;
public void NextCharacter()
{
characters[selectedCharacter].SetActive(false);
selectedCharacter = (selectedCharacter + 1) % characters.Length;
characters[selectedCharacter].SetActive(true);
}
public void PreviousCharacter()
{
characters[selectedCharacter].SetActive(false);
selectedCharacter--;
if (selectedCharacter < 0)
{
selectedCharacter += characters.Length;
}
characters[selectedCharacter].SetActive(true);
}
public void SelectCharacterInLobby()
{
PlayerPrefs.SetInt("selectedCharacter", selectedCharacter);
Destroy(GameObject.Find("DefaultCharacter"));
}
And here is my load character script which instantiate the selected character from main menu: public class LoadCharacterInGame : MonoBehaviour { public GameObject[] characterPrefabs; public Transform spawnPoint;
private void Start()
{
int selectedCharacter = PlayerPrefs.GetInt("selectedCharacter");
GameObject prefab = characterPrefabs[selectedCharacter];
GameObject clone = Instantiate(prefab, spawnPoint.position, Quaternion.identity);
}
}
Your answer
Follow this Question
Related Questions
[Solved] Destroy instantiated prefabs with a same tag, one by one, from last instantiated to first ? 2 Answers
How to set instantiated game object as child on collision in C# 0 Answers
C# Photon Networking - Preventing duplicate GameObjects from spawning on Join. 1 Answer
Moving a spawned object in a direction 1 Answer
Stuttering in build 0 Answers