Ejemplo n.º 1
0
    public void Start()
    {
        r = gameObject.GetComponent <randomize>();

        cameraTransform = Camera.main.transform;
        layers          = new Transform[transform.childCount];
        for (int i = 0; i < transform.childCount; i++)
        {
            layers[i] = transform.GetChild(i);

            leftIndex  = 0;
            rightIndex = layers.Length - 1;
        }


        foreach (Ball gameObj in GameObject.FindObjectsOfType <Ball>()) //find GameObjects that are balls
        {
            //print("found ball obj");
            if (!balls.Contains(gameObj.gameObject))                                            //if ball is not in list
            {
                print("added ball to list");

                balls.Add(gameObj.gameObject);                                                                  //add them to list
            }
        }
        transform.position = Vector3.zero;
    }
Ejemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        if (gameObject.transform.position.y > initialYPos)
        {
            gameObject.transform.Rotate(new Vector3(180, 0, 0));

            foreach (Transform child in transform)
            {
                randomize rs = child.gameObject.GetComponent <randomize>();
                if (child.gameObject.name != "plank_base" && child.gameObject.name != "plank_end")
                {
                    rs.flip();
                }
            }
        }
    }
Ejemplo n.º 3
0
    void createNew(string typeKey, int num)
    {
        //function for creating new objs: if list of type<shape> has object, setActive(true), put in background
        //								else create new object, put in background
        // Destroy has high cost -- when obj not needed, setActive(false), put into list of type<shape>;
        //Need to make sure all created object names are 'GameObject', due to ball script

        randomize rando = gameObject.GetComponent <randomize>();

        obstacles = rando.getObstacles();
        Debug.Log(string.Format("obstacle Name: {0}", obstacles.gameObject.name));
        List <GameObject> l = pool[typeKey];

        // foreach(GameObject g in l){
        //  if (g == null){
        //      l.Remove(g);
        //  }
        // }


        if (obstacles.childCount > 0)
        {
            foreach (Transform gObj in obstacles)              //add existing shapes to list (by type)
            {
                if (gObj.gameObject.CompareTag("c"))
                {
                    pool["c"].Add(gObj.gameObject);
                }
                else if (gObj.gameObject.CompareTag("r"))
                {
                    pool["r"].Add(gObj.gameObject);
                }
                else
                {
                    pool["p"].Add(gObj.gameObject);
                }
            }
        }



        //if(pool.TryGetValue(typeKey, out temp)){
        //	print("Invalid typeKey given to createNew"); //shouldn't return null
        //}
        //else


        if (l.Count == 0)                //if list is empty, add shape num times ; This case MAY BE REDUNDANT
        {
            switch (typeKey)
            {
            case "c":
                for (int i = 0; i < num; ++i)
                {
                    GameObject c = (GameObject)Instantiate(circlePrefab);                              //instantiate clones prefab
                    c.name = "GameObject";
                    c.transform.SetParent(obstacles);
                    addBuff(c, l);
                }
                break;

            case "r":
                for ( ; num != 0; num--)                       //no initialization is ok for for statement?
                {
                    GameObject r = (GameObject)Instantiate(rectanglePrefab);
                    r.name = "GameObject";
                    r.transform.SetParent(obstacles);
                    addBuff(r, l);
                }

                break;

            case "p":
                for (int i = 0; i < num; ++i)
                {
                    GameObject p = (GameObject)Instantiate(pentagonPrefab);
                    p.name = "GameObject";
                    p.transform.SetParent(obstacles);
                    addBuff(p, l);
                }
                break;

            default: break;
            }
        }
        else                   //there's something in list
        {
            int count = 0;
            foreach (Transform gObj in obstacles)
            {
                if (gObj.gameObject.CompareTag(typeKey))                         //find # of shape in THIS background
                {
                    count++;
                }
            }
            if (count >= num)                     //list has more/equal to num; excess
            {
                for (int i = 0; i < num; i++)
                {
                    GameObject   g    = l[i];
                    MultipleBall buff = g.GetComponent <MultipleBall>();
                    if (buff == null)                            //only regular shapes are set to active
                    {
                        g.SetActive(true);
                    }
                }
            }

            else if (count < num)                      //list has fewer elements than num
            {
                for (int i = 0; i < count; i++)
                {
                    GameObject   g    = l[i];
                    MultipleBall buff = g.GetComponent <MultipleBall>();
                    if (buff == null)                            //only regular shapes are set to active
                    {
                        g.SetActive(true);
                    }
                }
                switch (typeKey)
                {
                case "c":
                    for (int i = 0; i < num - count; ++i)
                    {
                        GameObject c = (GameObject)Instantiate(circlePrefab);
                        c.name = "GameObject";
                        c.transform.SetParent(obstacles);
                        addBuff(c, l);
                    }
                    break;

                case "r":
                    for (int i = 0; i < num - count; ++i)
                    {
                        GameObject r = (GameObject)Instantiate(rectanglePrefab);
                        r.name = "GameObject";
                        r.transform.SetParent(obstacles);
                        addBuff(r, l);
                    }

                    break;

                case "p":
                    for (int i = 0; i < num - count; ++i)
                    {
                        GameObject p = (GameObject)Instantiate(pentagonPrefab);
                        p.name = "GameObject";
                        p.transform.SetParent(obstacles);
                        addBuff(p, l);
                    }
                    break;
                }
            }
        }
    }