I have been trying to make a detection system for the game “pong”. But i can’t seem to find any way to detect if a goal has been scored
I have used tried two scripts both of which don’t work
The first one is:
public GameObject Ball; //assigning object
private float position;
void Start()
{
position = Ball.transform.position.x;
//gets the pos of x
}
void FixedUpdate()
{
if (position > 20 ||
position < -20) //checks if it's out of bounds
{
Debug.Log("Goal!");
}
}
The other one is the one i prefer works because it has a scoreboard with it, and i’m still a begginer so i don’t know how to use scoreboards.
private int Player1Score;
private int Player2Score;
public void Player1Scored()
{
Player1Score++;
Player1Text.GetComponent<TextMeshProUGUI>().text = Player1Score.ToString();
}
public void Player2Scored()
{
Player2Score++;
Player2Text.GetComponent<TextMeshProUGUI>().text = Player2Score.ToString();
}
Please help me i’ve been working on this for hours now