Exemplo n.º 1
0
    // TODO Add Exceptions when no prefabs are assigned in Editor

    void Awake()
    {
        Assert.IsNotNull(BugPrefab, "[Manager Awake] BugPrefab is NULL");
        Assert.IsNotNull(AttractorPrefab, "[Manager Awake] AttractorPrefab is NULL");

        // Create the Attractor
        GameObject attractor = Instantiate(AttractorPrefab, Vector3.zero, Quaternion.identity);

        attractor.name = "Attractor";
        attractor.tag  = "Attractor";

        // Create the Bugs empty parent object
        GameObject bugsRoot = new GameObject();

        bugsRoot.name = "Bugs";

        // Create the Bugs object pool
        bugsPool = new List <GameObject> ();
        for (int i = 0; i < Setup.maxBugs; i++)
        {
            // TODO make OBJ & BC reference the same thing, it's confusing here
            GameObject obj = Instantiate(BugPrefab, Vector3.zero, Quaternion.identity);
            Bug        bc  = obj.GetComponent <Bug> ();
            // obj.name = "Bug " + i + " (" + bc.gender + ")";
            obj.name             = "Bug " + i;
            obj.transform.parent = bugsRoot.transform;
            bc.AddAttractor(attractor);
            obj.SetActive(false);
            bugsPool.Add(obj);
        }

        // Setup the population slider min, max and default
        sliderBugsCount          = GameObject.Find("SliderBugsCount").GetComponent <Slider> ();
        sliderBugsCount.maxValue = (float)Setup.maxBugs;
        sliderBugsCount.minValue = 0f;
        sliderBugsCount.value    = Setup.startBugs;
        requestedBugs            = (int)sliderBugsCount.value;
        Debug.Log("-- END MAIN AWAKE --");
        Debug.Log("Requested bugs = " + requestedBugs);
    }