public void SetPlayerScore(int playerScore_) { i_ScorePos = 0; StartShowScoreboard(); if(scoreboardState == ScoreboardState.Start) { // We already determined that the player's score is greater than 5th place // Determine what position the score is gameObject.GetComponent<Cs_RewardSystem>().LoadRewardsFromFile(); ScoreboardInfo scoreInfo = gameObject.GetComponent<Cs_RewardSystem>().GetScoreboardInfo(); if (playerScore_ > (int)scoreInfo.Score_5th) i_ScorePos = 5; if (playerScore_ > (int)scoreInfo.Score_4th) i_ScorePos = 4; if (playerScore_ > (int)scoreInfo.Score_3rd) i_ScorePos = 3; if (playerScore_ > (int)scoreInfo.Score_2nd) i_ScorePos = 2; if (playerScore_ > (int)scoreInfo.Score_1st) i_ScorePos = 1; //print("Player Score Position: " + i_ScorePos); //print("Player Score: " + playerScore_); gameObject.GetComponent<Cs_RewardSystem>().SetScoreOnDeath(playerScore_); // Ask for the player's name scoreboardState = ScoreboardState.ReceiveName; } }
// Update is called once per frame void Update() { // Determine if the recent score goes on the Scoreboard // If we are currently accepting user input... if (scoreboardState == ScoreboardState.ReceiveName) { // Activate the icons go_DPad.GetComponent<Image>().enabled = true; go_LStick.GetComponent<Image>().enabled = true; go_Keyboard.GetComponent<Image>().enabled = true; #region Keyboard Input // Accept Keyboard Input string keyInput = Input.inputString; if (s_PlayerName.Length < 5 || s_PlayerName == "") s_PlayerName += keyInput; if (s_PlayerName.Length == 0) s_PlayerName = ""; // if (s_PlayerName.Contains(" ")) s_PlayerName.Replace(" ", ""); if(Input.GetKeyDown(KeyCode.Backspace) && s_PlayerName.Length > 1) { s_PlayerName = s_PlayerName.Substring(0, s_PlayerName.Length - 2); if (s_PlayerName.Length == 0) s_PlayerName = ""; } // Flash the text on screen f_flashTimer += Time.deltaTime; if (f_flashTimer >= 0.3f) HighScoreNameObject.GetComponent<Text>().text = "_" + s_PlayerName + "_"; else HighScoreNameObject.GetComponent<Text>().text = "_" + s_PlayerName + "|_"; if (f_flashTimer >= 0.6f) f_flashTimer = 0.0f; #endregion // Record input prevState = state; state = GamePad.GetState(playerIndex); // Accept Keypad Input #region Controller Input // If the player presses up, we need to take the last letter and 'increase' the character. if((state.ThumbSticks.Left.Y >= 0.1f && prevState.ThumbSticks.Left.Y < 0.1f) || (state.DPad.Up == ButtonState.Pressed && prevState.DPad.Up == ButtonState.Released)) { ScoreboardIncrementLetter(); } else if((state.ThumbSticks.Left.Y <= -0.1f && prevState.ThumbSticks.Left.Y > -0.1f) || (state.DPad.Down == ButtonState.Pressed && prevState.DPad.Down == ButtonState.Released)) { ScoreboardDecrementLetter(); } else if(((state.ThumbSticks.Left.X >= 0.1f && prevState.ThumbSticks.Left.X <= 0.1f) && s_PlayerName.Length < 5 ) || (state.DPad.Right == ButtonState.Pressed && prevState.DPad.Right == ButtonState.Released) && s_PlayerName.Length < 5) { s_PlayerName = s_PlayerName + "A"; } else if ((state.ThumbSticks.Left.X <= -0.1f && prevState.ThumbSticks.Left.X > -0.1f) || (state.DPad.Left == ButtonState.Pressed && prevState.DPad.Left == ButtonState.Released)) { if (s_PlayerName.Length > 0) s_PlayerName = s_PlayerName.Substring(0, s_PlayerName.Length - 1); } #endregion // Submit the name when buttons are pressed if (Input.GetKeyDown(KeyCode.Return) || (state.Buttons.A == ButtonState.Pressed && prevState.Buttons.A != ButtonState.Pressed)) { // Deactivate the icons go_DPad.GetComponent<Image>().enabled = false; go_LStick.GetComponent<Image>().enabled = false; go_Keyboard.GetComponent<Image>().enabled = false; // Store the player's name & score in the Reward system ScoreboardInfo scoreInfo = gameObject.GetComponent<Cs_RewardSystem>().GetScoreboardInfo(); //print("The Score Position: " + i_ScorePos); // Shift names down a position for (int i = 5; i > i_ScorePos; --i) { if (i == 5) scoreInfo.Name_5th = scoreInfo.Name_4th; if (i == 4) scoreInfo.Name_4th = scoreInfo.Name_3rd; if (i == 3) scoreInfo.Name_3rd = scoreInfo.Name_2nd; if (i == 2) scoreInfo.Name_2nd = scoreInfo.Name_1st; } // Store the new name if (i_ScorePos == 5) scoreInfo.Name_5th = s_PlayerName; if (i_ScorePos == 4) scoreInfo.Name_4th = s_PlayerName; if (i_ScorePos == 3) scoreInfo.Name_3rd = s_PlayerName; if (i_ScorePos == 2) scoreInfo.Name_2nd = s_PlayerName; if (i_ScorePos == 1) scoreInfo.Name_1st = s_PlayerName; // Reload the Scoreboard & display gameObject.GetComponent<Cs_RewardSystem>().SetScoreboardInformation(scoreInfo); VictoryTextObject.GetComponent<Text>().color = new Color(0, 0, 0, 0); HighScoreNameObject.GetComponent<Text>().color = new Color(0, 0, 0, 0); // Change state StartShowScoreboard(); scoreboardState = ScoreboardState.Display; } } else if (scoreboardState == ScoreboardState.Display) { // Otherwise... ShowLetters(); f_ScoreboardTimer += Time.deltaTime; if(f_ScoreboardTimer >= 10f) { GameObject player = GameObject.Find("Player"); player.GetComponent<Player>().Die(); player.GetComponent<Player>().Reset(); player.GetComponentInChildren<Avatar>().Reset(); gameObject.SetActive(false); gameObject.GetComponent<Canvas>().enabled = false; MainMenu.SetActive(true); MainMenu.GetComponent<Canvas>().enabled = true; buttonChanger.ChangeButton(buttonTarget); } } }
public void SetScoreboardState(ScoreboardState scoreboardState_) { scoreboardState = scoreboardState_; }