public void AddScore(PlayerScore.PlayerNr playerNr, ScoreDestructableComponent.DestructableType type) { SetScore(playerNr, buildings[playerNr].score + typeToPoints[type]); if (playAudio) { eventStart.start(); playAudio = false; } }
public void SetScore(PlayerScore.PlayerNr playerNr, int score) { buildings[playerNr].score = score; float multiplier = 2f; int visualizedScore = Mathf.RoundToInt(score * multiplier); if (buildings[playerNr].score > ((float)buildings[playerNr].MaxScore / multiplier)) { PlayerWon(playerNr); } string percentage = buildings[playerNr].MaxScore > 0 ? Mathf.Max(100 - ((float)visualizedScore / buildings[playerNr].MaxScore) * 100f, 0).ToString("0.0") : "100"; playerTextScores[(int)playerNr].text = playerNr + " = " + percentage + "%"; }
private void Start() { Transform tr = transform.parent; while (tr != null) { var ownerComponent = tr.GetComponent <HouseComponent>(); if (ownerComponent != null) { owner = ownerComponent.houseOwner; break; } else { tr = tr.parent; } } CanvasScore.instance.Register(owner, type); }
internal void Register(PlayerScore.PlayerNr owner, ScoreDestructableComponent.DestructableType type) { Debug.Log("Registering object " + type); buildings[owner].MaxScore += typeToPoints[type]; }
private void PlayerWon(PlayerScore.PlayerNr playerNr) { wonImage.gameObject.SetActive(true); PlayerScore.PlayerNr otherPlayer = playerNr == PlayerScore.PlayerNr.P1 ? PlayerScore.PlayerNr.P2 : PlayerScore.PlayerNr.P1; wonText.text = "PLAYER " + ((int)otherPlayer + 1) + " WON!"; }