// Used to deactivate certain world chunk in game
 public void Deactivate(WorldMovement world)
 {
     if (activeWorlds.Contains(world))
     {
         activeWorlds.Remove(world);
     }
 }
    public void SpawnChunk()
    {
        // Spawns a random world/level from a list of prefabs
        int prefabNumber = Random.Range(0, m_worldPrefabs.Count);

        Debug.Log("Prefab Number is: " + prefabNumber);

        // Checks if the game already has a copy of the chosen prefabb
        if (m_worldList.ContainsKey(prefabNumber) && m_worldList[prefabNumber].Count > 0)
        {
            // Goes through the list of copies and check for any inactive gameobject
            foreach (GameObject obj in m_worldList[prefabNumber])
            {
                // Once an inactive copy is found, activate and set it on the spawner position
                if (!obj.activeSelf)
                {
                    obj.SetActive(true);
                    obj.transform.position = m_spawnerTransform.position;

                    // Adds the world in the list of active worlds
                    // this list is useful for modifying speed later in development
                    WorldMovement wm = obj.GetComponent <WorldMovement>();
                    activeWorlds.Add(wm);

                    // Set the movement speed
                    wm.speed = -totalSpeed;

                    // Activates all the children of that world
                    // This means activate all the coins collected
                    foreach (Transform child in obj.transform)
                    {
                        child.gameObject.SetActive(true);
                    }

                    return;
                }
            }
        }

        // Instantiate certain prefab that has been created
        GameObject go = Instantiate(m_worldPrefabs[prefabNumber].gameObject, m_spawnerTransform.position, Quaternion.identity, m_levelParent);

        // Adds the copy of a prefab to list of all worlds
        if (!m_worldList.ContainsKey(prefabNumber))
        {
            m_worldList.Add(prefabNumber, new List <GameObject>());
        }

        m_worldList[prefabNumber].Add(go);

        // Adds it to list of active worlds
        WorldMovement world = go.GetComponent <WorldMovement>();

        activeWorlds.Add(world);

        // Set the movement speed
        world.speed = -totalSpeed;
    }
 // Use this for initialization
 void Start()
 {
     dropList = GetComponent<DropDownList> ();
     savedCoords = GameObject.Find ("World Data Storage").GetComponent<WorldSavedCoordinates>();
     movement = GameObject.Find ("World Loading Object").GetComponent<WorldMovement> ();
     coords = savedCoords.GetSavedLocations ();
     int numLocations = coords.GetLength (0) - 1;
     //Debug.Log (numLocations);
     for (int i = 0; i <= numLocations; i++) {
         string locationName = savedCoords.GetLocationName(i);
         DropDownListItem newButton = new DropDownListItem (locationName);
         dropList.AddItems (newButton);
     }
 }
    private void OnEnable()
    {
        NullChecker();

        // Resets the game
        foreach (WorldMovement world in activeWorlds)
        {
            world.gameObject.SetActive(false);
        }
        activeWorlds.Clear();
        distance          = 0;
        distanceText.text = "Distance: " + distance.ToString("0") + "m";

        // Checks if there is already an existing dictionary entry for the first prefab
        if (!m_worldList.ContainsKey(0) || m_worldList[0].Count <= 0)
        {
            // Create an entry in the dictionary for the first prefab
            m_worldList.Add(0, new List <GameObject>());

            // Instantiate a copy of the prefab
            GameObject go = Instantiate(m_worldPrefabs[0].gameObject, Vector3.zero, Quaternion.identity, m_levelParent);

            // Add it to the list in the dictionary
            m_worldList[0].Add(go);

            // Add it to the list of active worlds
            WorldMovement wm = go.GetComponent <WorldMovement>();
            activeWorlds.Add(wm);

            // Set the movement speed
            wm.speed = -totalSpeed;
        }
        else
        {
            // Goes through the list of copies and check for any inactive gameobject
            foreach (GameObject obj in m_worldList[0])
            {
                // Once an inactive copy is found, activate and set it on the zero position
                if (!obj.activeSelf)
                {
                    obj.SetActive(true);
                    obj.transform.position = Vector3.zero;

                    // Adds the world in the list of active worlds
                    // this list is useful for modifying speed later in development
                    WorldMovement wm = obj.GetComponent <WorldMovement>();
                    activeWorlds.Add(wm);

                    // Set the movement speed
                    wm.speed = -totalSpeed;

                    // Activates all the children of that world
                    // This means activate all the coins collected
                    foreach (Transform child in obj.transform)
                    {
                        child.gameObject.SetActive(true);
                    }

                    break;
                }
            }
        }
        m_playerAlive = true;
    }
Beispiel #5
0
 // Use this for initialization
 void Start()
 {
     control = (Control)(GameObject.FindGameObjectWithTag("Control").GetComponent("Control"));
     world   = (WorldMovement)(GameObject.FindGameObjectWithTag("World").GetComponent("WorldMovement"));
 }
Beispiel #6
0
 // Use this for initialization
 void Start()
 {
     control = (Control)(GameObject.FindGameObjectWithTag("Control").GetComponent("Control"));
     world = (WorldMovement)(GameObject.FindGameObjectWithTag("World").GetComponent("WorldMovement"));
 }