- Home /
Trouble with Destroying and instantiating game objects on new scene
I am very new to unity, this is the first project I have worked on. I have a scene where it is the player selection scene and then they click a button to select the player and put him in the new scene. This is where I am having trouble. I can load the new scene but it seems everything im trying is not working. (I have tried DontDestroyOnLoad but I am not sure if im implementing it correctly because my models are in a list and It was tricky) Any help would be appreciated. Sorry for sloppy or bad code/unity skills. im still learning :)
public class CharCreation : MonoBehaviour {
 private List<GameObject> models;
 private int selectionIndex = 0; //default indect of the model
 private GameObject ringO;
 private GameObject FlameStrike;
 static int temp;
 void Start()
 {
     
     models = new List<GameObject>();
     foreach (Transform T in transform)
     {
         models.Add(T.gameObject);
         T.gameObject.SetActive(false);
     }
     models[selectionIndex].SetActive(true);
 }public void Select(int index)
 {
     if (index == selectionIndex)
     {
         return;
     }
     if (index < 0 || index >= models.Count)
     {
         return;
     }
     models[selectionIndex].SetActive(false);
     selectionIndex = index;
     models[selectionIndex].SetActive(true);
     temp = selectionIndex;
 } public void ConfirmButton()
 {
     //PlayerPrefs.SetInt("CharacterSelected", selectionIndex);
     selectionIndex = temp;
     
     SceneManager.LoadScene("StartMap");
     
     models[selectionIndex].SetActive(true);
    
     print(selectionIndex);
 }
 
Answer by Gametrain8701 · Jul 16, 2017 at 05:51 AM
I'm to this too, but I don't see anything that would grab someone input for their character. And the selection index is set to private so it'll be difficult for the game to access that variable.@Rajnine
@JButler I can get it to select a character but my main problem is around #45 where I load a new scene. the line after that "models[selectionIndex].SetActive(true); I thought would make the character appear because that line of code did that earlier in the program. Is that what is used to make a character appear? the Selection Index is what the person selected and once they hit that confirm button that method loads up the new scene and I set that character to true which I thought would make them appear. could this be because the private index? Thanks for the reply also!
Your answer
 
 
             Follow this Question
Related Questions
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Unity - How to activate a canvas or gameobject when a scene restarts? 2 Answers
Why my object is ''destroyed'' when it's actually still in the scene? 0 Answers
GameObejct moves slower after reloading scene 2 Answers
Dynamically assign each ui.Text.text in list to the name of objects in another list 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                