예제 #1
0
 private void OnTriggerEnter(Collider other)
 {
     //Debug.Log(other.gameObject);
     if (other.gameObject.CompareTag(PowUpTag))
     {
         other.gameObject.SetActive(false);
         UpdateScore(PowUpSc);
         //set Ghosts to frightened mode
         GameObject[] g = GameObject.FindGameObjectsWithTag(GhostTag);
         for (int i = 0; i < g.Length; i++)
         {
             //Debug.Log(g[i]);
             //Debug.Log(i+" "+g.Length+g);
             g[i].GetComponent <GhostScript>().SetFrightenedState();
         }
     }
     else if (other.gameObject.CompareTag(CoinTag))
     {
         other.gameObject.SetActive(false);
         //increment score
         UpdateScore(CoinSc);
         //gameLogic for finished maze in UpdateScore()
     }
     else if (other.gameObject.CompareTag(GhostTag))
     {
         Debug.Log("here");
         //script instance
         GhostScript gs = other.gameObject.GetComponent <GhostScript>();
         //if the Ghost is frightened
         if (gs.GetState() == GhostScript.States.frightened)
         {
             //kill ghost
             //determine if ghost has already been killed in succession
             //other.transform.position = new Vector3(0, .5f, 0);
             UpdateScore(200);
             other.GetComponent <GhostScript>().ResetGhost();
         }
         else
         {
             //kill pacman, deduct one life, reload scene
             gameObject.transform.position = startVec;
             respawnTime = 5f;
             //Decrement Lives
             GameSaveScr gss = GameObject.Find("GameSave").GetComponent <GameSaveScr>();
             gss.PlayerLivesLeft--;
             Debug.Log(gss.PlayerLivesLeft);
             if (gss.PlayerLivesLeft == 0)
             {
                 gss.score = LocalScore;
                 //GameOver
                 gss.CurLevelName = "";
                 bool nhs   = false;//new high score
                 int  place = 0;
                 if (gss.score < PlayerSettingsScript.PlayerSettings.HighScore1)
                 {
                     if (gss.score < PlayerSettingsScript.PlayerSettings.HighScore2)
                     {
                         if (gss.score < PlayerSettingsScript.PlayerSettings.HighScore3)
                         {
                             if (gss.score < PlayerSettingsScript.PlayerSettings.HighScore4)
                             {
                                 if (gss.score < PlayerSettingsScript.PlayerSettings.HighScore5)
                                 {
                                     if (gss.score < PlayerSettingsScript.PlayerSettings.HighScore6)
                                     {
                                         if (gss.score < PlayerSettingsScript.PlayerSettings.HighScore7)
                                         {
                                             if (gss.score < PlayerSettingsScript.PlayerSettings.HighScore8)
                                             {
                                                 if (gss.score < PlayerSettingsScript.PlayerSettings.HighScore9)
                                                 {
                                                     if (gss.score < PlayerSettingsScript.PlayerSettings.HighScore10)
                                                     {
                                                         //Do nothing, not a high score
                                                     }
                                                     else
                                                     {
                                                         PlayerSettingsScript.PlayerSettings.HighScore10 = gss.score;
                                                         nhs   = true;
                                                         place = 10;
                                                     }
                                                 }
                                                 else
                                                 {
                                                     PlayerSettingsScript.PlayerSettings.HighScore10 = PlayerSettingsScript.PlayerSettings.HighScore9;
                                                     PlayerSettingsScript.PlayerSettings.HighScore9  = gss.score;
                                                     nhs   = true;
                                                     place = 9;
                                                 }
                                             }
                                             else
                                             {
                                                 PlayerSettingsScript.PlayerSettings.HighScore9  = PlayerSettingsScript.PlayerSettings.HighScore8;
                                                 PlayerSettingsScript.PlayerSettings.HighScore10 = PlayerSettingsScript.PlayerSettings.HighScore9;
                                                 PlayerSettingsScript.PlayerSettings.HighScore8  = gss.score;
                                                 nhs   = true;
                                                 place = 8;
                                             }
                                         }
                                         else
                                         {
                                             PlayerSettingsScript.PlayerSettings.HighScore10 = PlayerSettingsScript.PlayerSettings.HighScore9;
                                             PlayerSettingsScript.PlayerSettings.HighScore9  = PlayerSettingsScript.PlayerSettings.HighScore8;
                                             PlayerSettingsScript.PlayerSettings.HighScore8  = PlayerSettingsScript.PlayerSettings.HighScore7;
                                             PlayerSettingsScript.PlayerSettings.HighScore7  = gss.score;
                                             nhs   = true;
                                             place = 7;
                                         }
                                     }
                                     else
                                     {
                                         PlayerSettingsScript.PlayerSettings.HighScore10 = PlayerSettingsScript.PlayerSettings.HighScore9;
                                         PlayerSettingsScript.PlayerSettings.HighScore9  = PlayerSettingsScript.PlayerSettings.HighScore8;
                                         PlayerSettingsScript.PlayerSettings.HighScore8  = PlayerSettingsScript.PlayerSettings.HighScore7;
                                         PlayerSettingsScript.PlayerSettings.HighScore7  = PlayerSettingsScript.PlayerSettings.HighScore6;
                                         PlayerSettingsScript.PlayerSettings.HighScore6  = gss.score;
                                         nhs   = true;
                                         place = 6;
                                     }
                                 }
                                 else
                                 {
                                     PlayerSettingsScript.PlayerSettings.HighScore10 = PlayerSettingsScript.PlayerSettings.HighScore9;
                                     PlayerSettingsScript.PlayerSettings.HighScore9  = PlayerSettingsScript.PlayerSettings.HighScore8;
                                     PlayerSettingsScript.PlayerSettings.HighScore8  = PlayerSettingsScript.PlayerSettings.HighScore7;
                                     PlayerSettingsScript.PlayerSettings.HighScore7  = PlayerSettingsScript.PlayerSettings.HighScore6;
                                     PlayerSettingsScript.PlayerSettings.HighScore6  = PlayerSettingsScript.PlayerSettings.HighScore5;
                                     PlayerSettingsScript.PlayerSettings.HighScore5  = gss.score;
                                     nhs   = true;
                                     place = 5;
                                 }
                             }
                             else
                             {
                                 PlayerSettingsScript.PlayerSettings.HighScore10 = PlayerSettingsScript.PlayerSettings.HighScore9;
                                 PlayerSettingsScript.PlayerSettings.HighScore9  = PlayerSettingsScript.PlayerSettings.HighScore8;
                                 PlayerSettingsScript.PlayerSettings.HighScore8  = PlayerSettingsScript.PlayerSettings.HighScore7;
                                 PlayerSettingsScript.PlayerSettings.HighScore7  = PlayerSettingsScript.PlayerSettings.HighScore6;
                                 PlayerSettingsScript.PlayerSettings.HighScore6  = PlayerSettingsScript.PlayerSettings.HighScore5;
                                 PlayerSettingsScript.PlayerSettings.HighScore5  = PlayerSettingsScript.PlayerSettings.HighScore4;
                                 PlayerSettingsScript.PlayerSettings.HighScore4  = gss.score;
                                 nhs   = true;
                                 place = 4;
                             }
                         }
                         else
                         {
                             PlayerSettingsScript.PlayerSettings.HighScore10 = PlayerSettingsScript.PlayerSettings.HighScore9;
                             PlayerSettingsScript.PlayerSettings.HighScore9  = PlayerSettingsScript.PlayerSettings.HighScore8;
                             PlayerSettingsScript.PlayerSettings.HighScore8  = PlayerSettingsScript.PlayerSettings.HighScore7;
                             PlayerSettingsScript.PlayerSettings.HighScore7  = PlayerSettingsScript.PlayerSettings.HighScore6;
                             PlayerSettingsScript.PlayerSettings.HighScore6  = PlayerSettingsScript.PlayerSettings.HighScore5;
                             PlayerSettingsScript.PlayerSettings.HighScore5  = PlayerSettingsScript.PlayerSettings.HighScore4;
                             PlayerSettingsScript.PlayerSettings.HighScore4  = PlayerSettingsScript.PlayerSettings.HighScore3;
                             PlayerSettingsScript.PlayerSettings.HighScore3  = gss.score;
                             nhs   = true;
                             place = 3;
                         }
                     }
                     else
                     {
                         PlayerSettingsScript.PlayerSettings.HighScore10 = PlayerSettingsScript.PlayerSettings.HighScore9;
                         PlayerSettingsScript.PlayerSettings.HighScore9  = PlayerSettingsScript.PlayerSettings.HighScore8;
                         PlayerSettingsScript.PlayerSettings.HighScore8  = PlayerSettingsScript.PlayerSettings.HighScore7;
                         PlayerSettingsScript.PlayerSettings.HighScore7  = PlayerSettingsScript.PlayerSettings.HighScore6;
                         PlayerSettingsScript.PlayerSettings.HighScore6  = PlayerSettingsScript.PlayerSettings.HighScore5;
                         PlayerSettingsScript.PlayerSettings.HighScore5  = PlayerSettingsScript.PlayerSettings.HighScore4;
                         PlayerSettingsScript.PlayerSettings.HighScore4  = PlayerSettingsScript.PlayerSettings.HighScore3;
                         PlayerSettingsScript.PlayerSettings.HighScore3  = PlayerSettingsScript.PlayerSettings.HighScore2;
                         PlayerSettingsScript.PlayerSettings.HighScore2  = gss.score;
                         nhs   = true;
                         place = 2;
                     }
                 }
                 else
                 {
                     PlayerSettingsScript.PlayerSettings.HighScore10 = PlayerSettingsScript.PlayerSettings.HighScore9;
                     PlayerSettingsScript.PlayerSettings.HighScore9  = PlayerSettingsScript.PlayerSettings.HighScore8;
                     PlayerSettingsScript.PlayerSettings.HighScore8  = PlayerSettingsScript.PlayerSettings.HighScore7;
                     PlayerSettingsScript.PlayerSettings.HighScore7  = PlayerSettingsScript.PlayerSettings.HighScore6;
                     PlayerSettingsScript.PlayerSettings.HighScore6  = PlayerSettingsScript.PlayerSettings.HighScore5;
                     PlayerSettingsScript.PlayerSettings.HighScore5  = PlayerSettingsScript.PlayerSettings.HighScore4;
                     PlayerSettingsScript.PlayerSettings.HighScore4  = PlayerSettingsScript.PlayerSettings.HighScore3;
                     PlayerSettingsScript.PlayerSettings.HighScore3  = PlayerSettingsScript.PlayerSettings.HighScore2;
                     PlayerSettingsScript.PlayerSettings.HighScore2  = PlayerSettingsScript.PlayerSettings.HighScore1;
                     PlayerSettingsScript.PlayerSettings.HighScore1  = gss.score;
                     nhs   = true;
                     place = 1;
                 }
                 gss.score = 0;
                 PlayerSettingsScript.PlayerSettings.SaveSettings();
                 gss.SaveGame();
                 if (nhs)
                 {
                     PlayerPrefs.SetInt("score", LocalScore);
                     PlayerPrefs.SetInt("place", place);
                     SceneManager.LoadScene("NewHS Page", LoadSceneMode.Single);
                 }
                 else
                 {
                     SceneManager.LoadScene("StartMenu", LoadSceneMode.Single);
                 }
             }
             else
             {
                 //Keep on keeping on
             }
         }
     }
 }