- Home /
 
 
               Question by 
               Sinze · Nov 21, 2016 at 07:20 AM · 
                c#instantiatetagsforeachlist of lists  
              
 
              How to spawn an animal at each transform of a gameobject with a tag position in another scene?
 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 public class LevelManager : MonoBehaviour
 {
     public GameObject StartButton;
     Menu container;
     GameObject[] position;
     bool levelstarted = true;
 
     public List<Level> LevelNumber = new List<Level>();
     [System.Serializable]
     public class Level
     {
         public List<string> name = new List<string>();
         public List<GameObject> Map = new List<GameObject>();
         public List<GameObject> Animal = new List<GameObject>();
     }
 
         // Use this for initialization
         void Start()
     {
         container = StartButton.GetComponent<Menu>();
         DontDestroyOnLoad(gameObject);
     }
 
     // Update is called once per frame
     void Update()
     {
         if (container.start) {
             Instantiate(LevelNumber[container.level-1].Map[container.level - 1]);
             container.start = false;
             levelstarted = true;
         }
         if (levelstarted) {
 
             position = GameObject.FindGameObjectsWithTag("Position");
             foreach (GameObject location in position)
             {
                 Instantiate(LevelNumber[container.level - 1].Animal[Random.Range(0, LevelNumber[container.level - 1].Animal.Count)], location.transform);
 
 
             }
             levelstarted = false;
         }
            
         }
     }
  
 
               The above is a levelmanager. It is suppose to be at the menu of my game. I set it to , dontdestroyonload(); But as it moves to a new scene, i try finding all the gameobject with tag position and started spawning different animals. In my case, the above script does not spawn anything because of levelstarted = false;. If I removed the levelstarted = false; , then the games just keeps spawning none stop. Would really need help fast :(.
               Comment
              
 
               
              Your answer