Example #1
0
    public IEnumerator Retry(int number_of_letters, float speed)
    {
        livesbox.text = "Lives: " + lives;
        restart       = false;
        while (!restart)
        {
            if (Input.anyKey)
            {
                restart = true;
            }
            yield return(null);
        }
        for (int idx = 0; idx < number_of_letters; idx++)
        {
            if (idx == 0)
            {
                clone       = Instantiate(leadletter, new Vector2(0.0f, 0.0f), Quaternion.identity);
                letterclone = clone as GameObject;
                leader.tail.Add(letterclone);
                leader = (Leader)letterclone.GetComponent(typeof(Leader));
            }
            else
            {
                newletter = nextLetter(idx);
                // newletter is a prefab object, clone is an object, I needed to get it into a game object
                // to manage it correctly (add it to gameobject lists and get its script component)
                float x_placement = (float)idx;
                clone       = Instantiate(newletter, new Vector2(-x_placement / 2, 0.0f), Quaternion.identity);
                letterclone = clone as GameObject;
                leader.tail.Add(letterclone);
                letterscript = (Letter)letterclone.GetComponent(typeof(Letter));
                // needs to start as not Tail so beginning letters (that spawn on the leader)
                // dont end the game, changed to true after movement is applied
                letterscript.isTail = false;
                letterscript.isFood = false;
            }
            yield return(null);
        }
        alertbox.text = "";
        yield return(new WaitForSeconds(1f));

        textbox.text = "4";
        yield return(new WaitForSeconds(1f));

        textbox.text = "3";
        yield return(new WaitForSeconds(1f));

        textbox.text = "2";
        yield return(new WaitForSeconds(1f));

        textbox.text = "1";
        yield return(new WaitForSeconds(1f));

        leader.Begin(speed);
        SpawnFood(nextLetter());
        yield return(null);
    }
Example #2
0
    public IEnumerator startCoroutine(Boundary boundary, int lives, float speed)
    {
        guiclone      = GameObject.FindGameObjectWithTag("manager");
        manager       = (Manager)guiclone.GetComponent(typeof(Manager));
        guiclone      = GameObject.Find("Score Sound");
        scoresound    = (AudioSource)guiclone.GetComponent(typeof(AudioSource));
        guiclone      = GameObject.Find("Fail Sound");
        failsound     = (AudioSource)guiclone.GetComponent(typeof(AudioSource));
        this.lives    = lives;
        this.boundary = boundary;
        this.speed    = speed;
        restart       = false;
        clone         = Instantiate(leadletter, new Vector2(0.0f, 0.0f), Quaternion.identity);
        letterclone   = clone as GameObject;
        leader        = (Leader)letterclone.GetComponent(typeof(Leader));

        guiclone = GameObject.FindGameObjectWithTag("textbox");
        textbox  = (GUIText)guiclone.GetComponent(typeof(GUIText));
        guiclone = GameObject.FindGameObjectWithTag("lowerbox");
        lowerbox = (GUIText)guiclone.GetComponent(typeof(GUIText));
        guiclone = GameObject.FindGameObjectWithTag("alertbox");
        alertbox = (GUIText)guiclone.GetComponent(typeof(GUIText));
        guiclone = GameObject.FindGameObjectWithTag("livesbox");
        livesbox = (GUIText)guiclone.GetComponent(typeof(GUIText));

        textbox.text  = "5";
        lowerbox.text = "";
        alertbox.text = "";
        livesbox.text = "Lives: " + lives;
        yield return(new WaitForSeconds(1f));

        textbox.text = "4";
        yield return(new WaitForSeconds(1f));

        textbox.text = "3";
        yield return(new WaitForSeconds(1f));

        textbox.text = "2";
        yield return(new WaitForSeconds(1f));

        textbox.text = "1";
        yield return(new WaitForSeconds(1f));

        leader.Begin(speed);
        SpawnFood(nextLetter());
        yield return(null);
    }