示例#1
0
    void Update()
    {
        bool toSpawn = false;

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            UnityEngine.SceneManagement.SceneManager.LoadScene("StageSelect");
        }
        else if (Input.GetKeyDown(KeyCode.Q))
        {
            toSpawnChar = selectedPrefabCharacter;
            toSpawn     = true;
        }
        else if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            toSpawnChar = lincolnPrefab;
            toSpawn     = true;
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            toSpawnChar = grumpyPrefab;
            toSpawn     = true;
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            toSpawnChar = barbershopPrefab;
            toSpawn     = true;
        }
        if (Input.GetKeyDown(KeyCode.L))
        {
            toSpawnChar = luigiPrefab;
            toSpawn     = true;
        }

        bool levelWon = levelEnd.GoalIsMet();

        if (timeRunning)
        {
            timeElapsed += Time.deltaTime;
        }

        if (timeRunning && timeLimit > 0 && timeElapsed >= timeLimit)
        {
            // FAIL
            foreach (CharacterLife life in characterLives)
            {
                life.unityObject.GetComponent <CharacterController>().Kill();
            }
            characterLives.Clear();
            if (currCharacter)
            {
                currCharacter.GetComponent <CharacterController>().Kill();
                currCharacter = null;
            }
            timeRunning = false;
        }
        else if (levelWon)
        {
            float timeToWait = 1.3f;
            if (runOnceTextLol)
            {
                // AudioClip clip1 = (AudioClip) Resources.Load("Assets/sounds/winbarber");
                // audioSource.PlayOneShot(clip1);
                if (PlayerPrefs.GetString("SceneName") == "The Full Quartet")
                {
                    winbarbersource.PlayOneShot(winbarberclip);
                    timeToWait = 5f;
                }
                runOnceTextLol = false;
            }
            StartCoroutine(StartEndStage(timeToWait));
        }
        else if (toSpawn && !levelWon && canAddNextCharacter())
        {
            if (currCharacter != null && currCharacterLife != null)
            {
                characterLives.Add(currCharacterLife);
            }
            foreach (CharacterLife life in characterLives)
            {
                life.ResetToSpawn(spawnVector);
            }

            ResetComponents();

            currCharacter = Instantiate(toSpawnChar);
            var controllerScript = currCharacter.GetComponent <CharacterController>();
            currCharacter.transform.position = spawnVector;

            currCharacterLife              = new CharacterLife(currCharacter);
            controllerScript.mainRef       = this;
            controllerScript.characterLife = currCharacterLife;
        }
        else if (Input.GetKey(KeyCode.R))
        {
            foreach (CharacterLife life in characterLives)
            {
                Destroy(life.unityObject);
            }
            characterLives.Clear();
            if (currCharacter)
            {
                Destroy(currCharacter);
            }
            currCharacter     = null;
            currCharacterLife = null;

            nBarbershopCurr = 0;
            nGrumpyCurr     = 0;
            nLincolnCurr    = 0;

            levelEnd.ResetProgress();

            timeElapsed = 0;
            timeRunning = true;
        }
        else if (Input.GetKeyDown(KeyCode.P))
        {
            if (currCharacter != null && currCharacterLife != null)
            {
                characterLives.Add(currCharacterLife);
            }
            foreach (CharacterLife life in characterLives)
            {
                life.ResetToSpawn(spawnVector);
            }
            currCharacter     = null;
            currCharacterLife = null;
        }
        else if (currCharacter)
        {
            keysPressed = new List <KeyInputType>();
            if (Input.GetKey(KeyCode.Space))
            {
                keysPressed.Add(KeyInputType.Jump);
            }
            if (Input.GetKey("left"))
            {
                keysPressed.Add(KeyInputType.Left);
            }
            if (Input.GetKey("right"))
            {
                keysPressed.Add(KeyInputType.Right);
            }
            if (Input.GetKey(KeyCode.E))
            {
                keysPressed.Add(KeyInputType.Action);
            }
            horizontal = Input.GetAxis("Horizontal");
        }
    }