示例#1
0
//kill the player
        private void KillMe()
        {
            followCam.SetTarget(Instantiate(explosion, transform.position, transform.rotation).transform);
            rb.velocity = Vector3.zero;
            Destroy(gameObject);
            FindObjectOfType <LevelManager_rescuethem>().Respawn();
        }
        // Update is called once per frame
        private void Update()
        {
            //mostly the code here is to detect which state the game is in, and set the correct canvas and UI on
            if (state == "win")
            {
                if (SceneManager.GetActiveScene().name == "mainMenu")
                {
                    nextLevel();
                    return;
                }


                followCam.SetTarget(goal.transform);
                goal.SetActive(false);
                xcanvas.SetActive(false);
                Destroy(activePlayer);
                if (SceneManager.GetActiveScene().name == lastScene)
                {
                    pauseNextButton.onClick.RemoveAllListeners();
                    pauseNextButton.GetComponentInChildren <TextMeshProUGUI>().text = "Main Menu";
                    pauseNextButton.onClick.AddListener(MainMenu);
                }

                double score = timer;
                if (gameOnManager != null)
                {
                    if (!submittedScore)
                    {
                        //this code here is to submit the score if GameOn was on after a level is completed.
                        submittedScore = true;
                        gameOnManager.SubmitScore((int)(score * 1000f), lives, gameOnManager.activeMatch);
                        Debug.Log(score);
                    }
                }
                else
                {
                    youwinText.SetActive(true);
                    score = (int)(score * 1000f);
                    finalTimeText.text = TimeToString(timer) + " seconds";
                }
            }

            switch (state)
            {
            case "gameover":

                Destroy(activePlayer);
                Destroy(goal);
                break;

            case "active":
            {
                if (SceneManager.GetActiveScene().name != "mainMenu")
                {
                    xcanvas.SetActive(true);
                    timer         += Time.deltaTime;
                    timerText.text = TimeToString(timer);
                }

                break;
            }
            }

            if (state != "standby")
            {
                if (state != "pause")
                {
                    return;
                }
            }
        }