Hello! I'm creating a pong on my own and I have this issue with the score system.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class leftScript : MonoBehaviour
{
public int player2Score = 0;
public Text score2;
public bool ballAlive = true;
public void addScore()
{
Debug.Log("Collision detected!");
player2Score++;
score2.text = player2Score.ToString();
}
private void OnCollisionEnter2D(Collision2D collision)
{
addScore();
ballAlive = false;
}
}
here is the code, I have colliders setup on left and right and each time ball hits them score increases respectfully. the porblem is:
at the start of the game score increases by 1 instantly for each player, after that it works perfectly fine