I am pretty new to unity and am trying to create a simple game where two players spawn in and run around the map touching little pads. when you touch the pads they change colour to that of the player and are given a point, the player with the most points at the end of the time given (30 seconds) wins. i have this working, now what i want to do is at the end of the 30 seconds is for a screen to pop up saying which player won that round, and then the amount of round wins they have, e.g. 1-0. then i want it to disappear and start another round. how could i do this?
These are the scripts i have:
Score Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
public float playerOneScore;
public float playerTwoScore;
public Text playerOneScoreText;
public Text playerTwoScoreText;
// Start is called before the first frame update
void Start()
{
playerOneScore = 0f;
playerTwoScore = 0f;
playerOneScoreText.text = "0";
playerTwoScoreText.text = "0";
}
void Update()
{
playerOneScoreText.text = playerOneScore.ToString();
playerTwoScoreText.text = playerTwoScore.ToString();
}
}
The Timer script that gives a countdown to the games start and counts down the amount of time left in the round
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Coutndown : MonoBehaviour
{
float timeLeft = 3.0f;
float gameTimeLeft = 30.0f;
public Text text;
public Text gameTime;
public Text playerOneScore;
public Text playerTwoScore;
public GameObject spawnObject;
PlayerSpawn spawnScript;
public GameObject playerOne;
PlayerController playerOneScript;
public GameObject playerTwo;
PlayerController playerTwoScript;
public bool startGame;
public bool endGame;
void Start()
{
spawnScript = spawnObject.GetComponent<PlayerSpawn>();
playerOneScript = playerOne.GetComponent<PlayerController>();
playerTwoScript = playerTwo.GetComponent<PlayerController>();
startGame = false;
endGame = false;
}
void Update()
{
if (spawnScript.playersSpawned)
{
StartCountdown();
}
}
void StartCountdown()
{
timeLeft -= Time.deltaTime;
text.text = Mathf.Round(timeLeft).ToString();
if (timeLeft < 1)
{
text.text = "GO!";
}
if (timeLeft < 0)
{
playerOneScript.speed = 10f;
playerTwoScript.speed = 10f;
text.text = "";
StartGame();
}
}
void StartGame()
{
gameTimeLeft -= Time.deltaTime;
gameTime.text = Mathf.Round(gameTimeLeft).ToString();
if(gameTimeLeft < 0)
{
playerOneScript.speed = 0f;
playerTwoScript.speed = 0f;
gameTime.text = "";
playerOneScore.text = "";
playerTwoScore.text = "";
}
}
}
A script that detects if a player touches its pad and gives them a point/takes away a point
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GetPoints : MonoBehaviour
{
Renderer rend;
public GameObject gameManager;
Score scoreScript;
public bool bluePad;
public bool redPad;
public bool whitePad;
public bool playerOnePoint;
public bool PlayerTwoPoint;
void Start()
{
rend = GetComponent<Renderer>();
scoreScript = gameManager.GetComponent<Score>();
bluePad = false;
redPad = false;
whitePad = true;
playerOnePoint = true;
PlayerTwoPoint = true;
}
void OnTriggerEnter(Collider collider)
{
if (collider.gameObject.tag == "PlayerOne" && whitePad == true)
{
whitePad = false;
bluePad = true;
rend.material.SetColor("_Color", Color.blue);
playerOnePoint = true;
if (playerOnePoint)
{
scoreScript.playerOneScore++;
playerOnePoint = false;
}
}
if (collider.gameObject.tag == "PlayerOne" && redPad == true)
{
redPad = false;
bluePad = true;
rend.material.SetColor("_Color", Color.blue);
playerOnePoint = true;
if (playerOnePoint)
{
scoreScript.playerOneScore++;
scoreScript.playerTwoScore--;
playerOnePoint = false;
}
}
if (collider.gameObject.tag == "PlayerTwo" && whitePad == true)
{
whitePad = false;
redPad = true;
rend.material.SetColor("_Color", Color.red);
PlayerTwoPoint = true;
if (PlayerTwoPoint)
{
scoreScript.playerTwoScore++;
PlayerTwoPoint = false;
}
}
if (collider.gameObject.tag == "PlayerTwo" && bluePad == true)
{
redPad = true;
bluePad = false;
rend.material.SetColor("_Color", Color.red);
PlayerTwoPoint = true;
if (PlayerTwoPoint)
{
scoreScript.playerOneScore--;
scoreScript.playerTwoScore++;
PlayerTwoPoint = false;
}
}
}
}