I need help on a win/lose script.

I am making a pong clone, and if the ball goes off one side of the screen, it will say “You lose” but if it goes off the other, it will say “You Win”

Please write it for me, since I don’t know how to script that much and this has been frustrating me for a long time.

Other things you may need to know:

I’m writing in C#

It’s 3d

Position for the You Lose side: -13.89, 0, 0

Position for the You Win Side: 13.89, 0, 0

Firstly, you will want to create a UI text to show the message.
Right click in the hierachy and go UI → text.
Attach this script to the UI text you just made.

using UnityEngine.UI;   //This is important as it allows you to edit UI elements
public Transform theBall;  //This is the position of the ball, once the code is written and attached, drag the ball gameobject onto this in the Inspector

void Start(){
      GetComponent<Text>().enabled = false;  //Hide the text when the game starts
}
void Update(){
      if (theBall.position.x >= 13.89){   //Check if the ball goes off to the right
             GetComponent<Text>().enabled = true;   //Show the text
             GetComponent<Text>().text = "You win";    //Set the text to "You win"
             Time.timeScale = 0;   //Pause the game
      }
     else if (theBall.position.x <= -13.89){    //Check if the ball goes off to the left
             GetComponent<Text>().enabled = true;   //Show the text
             GetComponent<Text>().text = "You lose";    //Set the text to "You lose"
             Time.timeScale = 0;   //Pause the game
      }
}

I have not tested this but it should work… :confused: