<commit_before>﻿using System;
using Client.Common;
using Client.Game;
using UnityEngine;

namespace Client.Controllers
{
    // Create a ball. Once there is a Goal, create a new
    // ball at the given time frame.
    public class BallController : MonoBehaviour
    {
        [SerializeField]
        [Tooltip("The soccer ball prefab")]
        private GameObject prefabBall;

        private GameObject currentBall;

        // --- Messages ---
        private void Start()
        {
            if(prefabBall == null)
            {
                throw new Exception("Prefab should not be null!");
            }

            CreateBall();

            var p1Goal = Goals.FindPlayerOneGoal().GetComponent<TriggerObservable>();
            var p2Goal = Goals.FindPlayerTwoGoal().GetComponent<TriggerObservable>();

            p1Goal.TriggerEnter += OnGoal;
            p2Goal.TriggerEnter += OnGoal;
        }


        // --- Functions ---

        // Create a ball. Removes the old one if there is one.
        private void CreateBall()
        {
            if(currentBall != null)
            {
                Destroy(currentBall);
            }
            currentBall = Instantiate(prefabBall);
            currentBall.name = Ball.Name;
        }

        private void OnGoal(Collider _)
        {
            Invoke("CreateBall", 5);
        }

    }
}<commit_msg>Make sure a ball can't happen while a goal has already happened!<commit_after>﻿using System;
using Client.Common;
using Client.Game;
using UnityEngine;

namespace Client.Controllers
{
    // Create a ball. Once there is a Goal, create a new
    // ball at the given time frame.
    public class BallController : MonoBehaviour
    {
        [SerializeField]
        [Tooltip("The soccer ball prefab")]
        private GameObject prefabBall;

        private GameObject currentBall;
        // property to ensure we don't try and create a ball while
        // creating a ball
        private bool isGoal;

        // --- Messages ---
        private void Start()
        {
            if(prefabBall == null)
            {
                throw new Exception("Prefab should not be null!");
            }

            isGoal = false;
            var p1Goal = Goals.FindPlayerOneGoal().GetComponent<TriggerObservable>();
            var p2Goal = Goals.FindPlayerTwoGoal().GetComponent<TriggerObservable>();

            p1Goal.TriggerEnter += OnGoal;
            p2Goal.TriggerEnter += OnGoal;

            CreateBall();
        }


        // --- Functions ---

        // Create a ball. Removes the old one if there is one.
        private void OnGoal(Collider _)
        {
            if(!isGoal)
            {
                isGoal = true;
                Invoke("CreateBall", 5);
            }
        }

        private void CreateBall()
        {
            if(currentBall != null)
            {
                Destroy(currentBall);
            }
            currentBall = Instantiate(prefabBall);
            currentBall.name = Ball.Name;
            isGoal = false;
        }
    }
}
{'fraction_non_alphanumeric': 0.09165035877364644, 'fraction_numerical': 0.0032615786040443573, 'mean_word_length': 1.5729865771812082, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6428291', 'n_tokens_mistral': 848, 'n_tokens_neox': 791, 'n_words': 221}