#Making pong! score problem

1 messages · Page 1 of 1 (latest)

hard wedge
#

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

#

heres the setup

gloomy geyser
#

You don't check WHAT they collide with. The paddles immediately collide with the Left and Right collider walls

#

You have it so if ANYTHING collides, you add score

hard wedge
#

ohhh

#

damn okay

#

thank's I'll try to fix that!