Does anyone know what to do here?

I’m trying to set leftscore to 0 but it isn’t working. There aren’t any errors.

My GameController and GameEnder script

GameController:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameController : MonoBehaviour
{
public static GameController instance { get; private set; }

private GameEnder gameEnder;

[SerializeField] private UIManager uiManager;

[SerializeField] private int scoreToWin = 2;
[SerializeField] public int leftScore;
[SerializeField] private int rightScore;

[SerializeField] private bool inMenu;

private Ball ball;

[SerializeField] private Paddle leftPaddle;
[SerializeField] private Paddle rightPaddle;

private void Awake()
{
    instance = this;
    ball = GameObject.FindGameObjectWithTag("Ball").GetComponent<Ball>();
}

public void Score(Paddle.Side side)
{
    if (side == Paddle.Side.Left)
        leftScore++;
    else if (side == Paddle.Side.Right)
        rightScore++;

    uiManager.UpdateScoreText(leftScore, rightScore);

    if (IsGameOver())
    {
        if (inMenu)
        {
            ResetGame();
            leftScore = rightScore = 0;
        }
        else
            ball.gameObject.SetActive(false);
    }
    else
    {
        ResetGame();
    }
}

private bool IsGameOver()
{
    bool result = false;

    if (leftScore >= scoreToWin || rightScore >= scoreToWin)
        result = true;

    return result;
}

private void ResetGame()
{
    leftPaddle.Reset();
    rightPaddle.Reset();
}

}

GameEnder:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameEnder2 : MonoBehaviour
{
public GameController playerobj;

private void TriggerEnter2D(Collision2D collision)
{
    if (collision.collider.tag == "Ball")
    
        playerobj.leftScore = 0;
    }
}

Does it run the collision code?

private void TriggerEnter2D(Collision2D collision)
{
    Debug.Log("Something hit");
    if (collision.collider.tag == "Ball") {
        Debug.Log("Ball hit");
        playerobj.leftScore = 0;
    }
}

Look for the debug logs in the console.

Hi Paperripoff,

Does the collider attached to the gameobject with your GameEnder script is set as a trigger ?
167671-capture-decran-2020-09-17-a-114027.png