Hi, i’m working on a project which involves a Rock, Paper, Scissors game within it. I have the game aspect sorted but I am struggling with the scoring system of the game.
So far I have 3 different public voids for each option
public void OnRockPointerClick()
{
randomInt = (Random.Range(1, 4));
tm = (TextMesh)GameObject.Find("Score").GetComponent<TextMesh>();
tm.text = "";
if (randomInt ==(1))
{
Debug.Log("Draw");
tm = (TextMesh)GameObject.Find("decision").GetComponent<TextMesh>();
tm.text = "DRAW";
}
if (randomInt ==(2))
{
Debug.Log("Lose");
CPUscore += 1;
tm = (TextMesh)GameObject.Find("decision").GetComponent<TextMesh>();
tm.text = "CPU WIN";
tm = (TextMesh)GameObject.Find("cpupoint").GetComponent<TextMesh>();
tm.text += "X ";
}
if (randomInt == (3))
{
Debug.Log("Win");
PlayerScore += 1;
tm = (TextMesh)GameObject.Find("decision").GetComponent<TextMesh>();
tm.text = "PLAYER WIN";
tm = (TextMesh)GameObject.Find("playerpoint").GetComponent<TextMesh>();
tm.text += "X ";
}
I know this method probably isn’t the best way to do it but it’s what i’m going with, i’m not too worried about cleaning up my code at the moment as well.
My code for when either the player or computer wins is,
void Update()
{
if (PlayerScore == 3)
{
Debug.Log("You win!!");
tm = (TextMesh)GameObject.Find("Score").GetComponent<TextMesh>();
tm.text = "YOU WIN";
tm = (TextMesh)GameObject.Find("playerpoint").GetComponent<TextMesh>();
tm.text = "";
tm = (TextMesh)GameObject.Find("cpupoint").GetComponent<TextMesh>();
tm.text = "";
tm = (TextMesh)GameObject.Find("decision").GetComponent<TextMesh>();
tm.text = "";
CPUscore.Equals(0);
PlayerScore.Equals(0);
}
if (CPUscore == 3)
{
Debug.Log("You lose!!");
tm = (TextMesh)GameObject.Find("Score").GetComponent<TextMesh>();
tm.text = "YOU LOSE";
tm = (TextMesh)GameObject.Find("playerpoint").GetComponent<TextMesh>();
tm.text = "";
tm = (TextMesh)GameObject.Find("cpupoint").GetComponent<TextMesh>();
tm.text = "";
tm = (TextMesh)GameObject.Find("decision").GetComponent<TextMesh>();
tm.text = "";
CPUscore.Equals(0);
PlayerScore.Equals(0);
}
}
I’m having the problem though that (also sorry if this does not make much sense) when a player reaches 3 points it only counts for that button click, its not an overall counter.
So, if a player chooses Rock twice and wins then Scissors once and also wins, the game should count this as having 3 points and the player should win the game. However currently it is Rock 2 points, Scissors 1 point, which doesn’t activate the win sequence.
Any help with this would be great thanks!