void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Player" || other.tag == "Disappear") { //sit down if (other.transform.childCount > 0) { other.transform.GetChild(0).gameObject.SetActive(false); other.GetComponent <SpriteRenderer>().sprite = sittingImg; } StartCoroutine(Freeze(0.5f)); other.transform.eulerAngles = new Vector3(0, 0, 0); other.transform.position = new Vector3(x, y, 0); // Locks the cheatbar var allMeetMinimumScore = true; // if(!firstSeating){ // barAudio.Play(); // } var counter = 0; foreach (GameObject CheatBar in CheatBars) { CheatBar CheatBar_Item = CheatBar.GetComponent <CheatBar>(); CheatBar_Item.cheatBarLock(); if (bars[counter] < CheatBar_Item.size) { //update temp bar value barAudio.Play(); bars[counter] = CheatBar_Item.size; } if (CheatBar_Item.size < 0.3f) { allMeetMinimumScore = false; } counter += 1; } inSnapPos = true; if (allMeetMinimumScore) { LevelControl.instance.youWin(); } } }
public void youWin() { // anim.SetBool("gameover", true); winSound.Play(); if (levelPassed < sceneIndex) { PlayerPrefs.SetInt("LevelPassed", sceneIndex); } //score float barScoresTotal = 0; int numberOfBars = 0; var firstStarCheckMeet = true; var secondStarCheckMeet = true; foreach (GameObject CheatBar in CheatBars) { numberOfBars += 1; } foreach (GameObject CheatBar in CheatBars) { CheatBar CheatBar_Item = CheatBar.GetComponent <CheatBar>(); Debug.Log(CheatBar_Item.size); barScoresTotal += CheatBar_Item.size * (90 / numberOfBars); if (CheatBar_Item.size < 0.3f) { firstStarCheckMeet = false; } if (CheatBar_Item.size < optimalBarForSecondStar) { secondStarCheckMeet = false; } } score = barScoresTotal + int.Parse(timerTextUI.text) * 0.3; scoreInt = (int)score; scoreTextUI.text = "Score: " + scoreInt; //highest score if (score > PlayerPrefs.GetInt("HighestScore" + sceneIndex)) { PlayerPrefs.SetInt("HighestScore" + sceneIndex, scoreInt); Debug.Log("Highscore: " + scoreInt); } scoreHighestTextUI.text = "Highest Score: " + PlayerPrefs.GetInt("HighestScore" + sceneIndex); // star scoring system if (firstStarCheckMeet) { playerTitleText.text = "Common Cheater"; star1.gameObject.SetActive(true); } if (secondStarCheckMeet) { playerTitleText.text = "Pro Cheater"; star2.gameObject.SetActive(true); } if (int.Parse(timerTextUI.text) >= optimalTimeForThirdStar) { if (star2.gameObject.activeSelf) { playerTitleText.text = "Master Cheater"; star3.gameObject.SetActive(true); } else { star2.gameObject.SetActive(true); } } endGamePanel.gameObject.SetActive(true); gameOverImage.enabled = false; restartButton.gameObject.SetActive(false); gameHasEnded = true; player.GetComponent <PlayerController>().FreezeMovement(); foreach (GameObject invigilator in invigilators) { invigilator.GetComponent <TeacherNPC>().FreezeMovement(); } }