Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.R))
        {
            Application.LoadLevel(0);
        }
        // CONTROLLING THE SCREEN CAMERA
        if ((Input.GetKeyDown(KeyCode.Space) || Input.GetButtonDown("joystick button 1")) && currentScreen != 3)
        {
            if (currentScreen == 0 || currentScreen == -1)
            {
                // advance a screen
                currentScreen += 1;

                AudioSource.PlayClipAtPoint(screenTransition, transform.position);
            }
            else if (currentScreen == 1)
            {
                // only if middle ship is selected
                int shipCheck = PlayerPrefs.GetInt("SelectedShip");
                //Debug.Log("shipcheck: " + shipCheck);
                if (shipCheck == 2)
                {
                    currentScreen += 1;
                    AudioSource.PlayClipAtPoint(screenTransition, transform.position);
                }
                else
                {
                    AudioSource.PlayClipAtPoint(errorSound, transform.position);
                }
            }
            else if (currentScreen == 2)
            {
                // if we are on go!
                MissionControl mC = (MissionControl)missionScreen.GetComponent(typeof(MissionControl));
                //Debug.Log(mC.curRow);
                if (mC.curRow == 5)
                {
                    if (mC.curCol == 3)
                    {
                        AudioSource.PlayClipAtPoint(screenTransition, transform.position);
                        currentScreen += 1;
                    }
                }
            }

            if (currentScreen > 3)
            {
                currentScreen = 0;
            }
        }
        else if ((Input.GetKeyDown(KeyCode.Backspace) || Input.GetButtonDown("joystick button 2")) && currentScreen != 3)
        {
            currentScreen -= 1;

            if (currentScreen <= -1)
            {
                currentScreen = -1;
            }

            if (currentScreen == 0)
            {
                AudioSource.PlayClipAtPoint(screenTransition, transform.position);
            }
            else if (currentScreen == 1)
            {
                //currentScreen += 1;
                AudioSource.PlayClipAtPoint(screenTransition, transform.position);
            }
        }

        if (currentScreen == -1)
        {
            cam.transform.position = Vector3.Lerp(cam.transform.position, pos0, 3.0f * Time.deltaTime);
        }

        // GAMESTATES
        if (currentScreen == 0)           // title
        {
            cam.transform.position = Vector3.Lerp(cam.transform.position, pos1, 3.0f * Time.deltaTime);
        }

        if (currentScreen == 1)           // hanger
        {
            cam.transform.position = Vector3.Lerp(cam.transform.position, pos2, 3.0f * Time.deltaTime);
        }

        if (currentScreen == 2)           // customize
        {
            cam.transform.position = Vector3.Lerp(cam.transform.position, pos3, 3.0f * Time.deltaTime);

            GameObject demoPlayer = GameObject.FindGameObjectWithTag("shipIcon");
            if (demoPlayer)
            {
                demoPlayer.tag = "Player";
            }

            // disable game cause we are customizing yo!
            if (isLive)
            {
                gameOverPrefab.SetActive(false);
                levelScreen.SetActive(false);
                LevelLogic LL = (LevelLogic)levelScreen.GetComponent(typeof(LevelLogic));
                LL.disableTimer();
                isLive = false;
            }
        }

        if (currentScreen == 3)           // play

        {
            if (cam.transform.position != pos4)
            {
                cam.transform.position = Vector3.Lerp(cam.transform.position, pos4, 3.0f * Time.deltaTime);
            }

            GameObject demoPlayer = GameObject.Find("ShipIcon");
            demoPlayer.tag = "shipIcon";
            LevelLogic LL = (LevelLogic)levelScreen.GetComponent(typeof(LevelLogic));


            if (isLive && LL.gameOver == true)
            {
                gameOver = true;
                gameOverPrefab.SetActive(true);
            }
            else
            {
                gameOver = false;
                gameOverPrefab.SetActive(false);
            }


            // trigger is live
            if (!isLive)
            {
                // enable the renderer
                levelScreen.SetActive(true);
                LL.reset();
                LL.enableTimer();
                isLive         = true;
                LL.currentWave = highestWave;
            }
        }
    }