- Home /
 
               Question by 
               TheDarkAvengerz · Dec 19, 2018 at 08:22 PM · 
                c#unity 5prefabsdropdown  
              
 
              How Can I load Different Prefab on Combobox Change?
Hi! I have actually a problem to load my prefab on my scene on my dropdownlist change the error is this one. The Object you want to instantiate is null.
 Dropdown m_Dropdown;
 GameObject[] Ennemies = new GameObject[3];
 GameObject EnnemiCube;
 Button BtnRetour;
 
 void Start()
 {
     Ennemies[0] = Resources.Load("Prefabs/Prf.Ennemi1") as GameObject;
     Ennemies[1] = Resources.Load("Prefabs/Prf.Ennemi2") as GameObject;
     Ennemies[2] = Resources.Load("Prefabs/Prf.Ennemi3") as GameObject;
     EnnemiCube = GameObject.Find("TemplateEnnemi");
     EnnemiCube = Ennemies[0];
     Instantiate(EnnemiCube, new Vector3(- 28f, 10f, 85f), Quaternion.identity);
     EnnemiCube.transform.localScale = new Vector3(20f, 20f, 20f);
     m_Dropdown = GetComponentInChildren<Dropdown>();
     m_Dropdown.onValueChanged.AddListener(delegate { DropdownValueChanged(m_Dropdown); });
     BtnRetour = GameObject.Find("BtnRetour").GetComponent<Button>();
     BtnRetour.onClick.AddListener(() => OuvrirSceneMenu());
 }
   
 void Update()
 {
     Rotation();
 }
 public void OuvrirSceneMenu()
 {
     SceneManager.LoadScene("Scn.Menu", LoadSceneMode.Single);
 }
 public void Rotation() => Ennemies[m_Dropdown.value].transform.Rotate(new Vector3(0, Input.GetAxis("Horizontal"), 0));
 public void DropdownValueChanged(Dropdown dropdown)
 {
     switch (dropdown.value)
     {
         case 0 :
             EnnemiCube = Instantiate(Ennemies[0], transform.position, Quaternion.identity) as GameObject; 
             break;
         case 1:
             EnnemiCube = Instantiate(Ennemies[1], transform.position, Quaternion.identity) as GameObject;
             break;
         case 2:
             EnnemiCube = Instantiate(Ennemies[2], transform.position, Quaternion.identity) as GameObject;
             break;
     }
     
 }
Thanks!
               Comment
              
 
               
              Your Resources.Load statements aren't resolving objects. Verify the path you're referring to and try again. Also, if Ennemi1 is a file extension, they cannot be used for paths in Resources.Load.
Your answer
 
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to change the quality of the game while playing it? 1 Answer
PrefabUtility does not exist? 1 Answer
Deleting a prefab with onclick/touch 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                