Example #1
0
        public bool OnGoalScored()
        {
            if (!IsGameReady || IsGameOver)
            {
                return(false);
            }

            GoalScoredEvent?.Invoke(this, null);

            Debug.Log("Goooooaaaalllll!");

            _score++;

            if (null != GameUIManager.Instance.GameGameUI)
            {
                GameUIManager.Instance.GameGameUI.PlayerHUD.UpdateScore(_score);
            }

            if (_goal > 0 && _score >= _goal)
            {
                Debug.Log("You win this round!");
                RoundWonEvent?.Invoke(this, null);
                return(true);
            }

            return(true);
        }
Example #2
0
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == m_Ball.tag)
        {
            // Ball collided, goal scored

            // Trigger visual
            var exp = (GameObject)Instantiate(
                m_Explosion, m_Ball.transform.position, Quaternion.identity);
            var particle = exp.GetComponent <ParticleSystem>();
            particle.Play();
            m_Ball.SetActive(false);
            Destroy(exp, 5f);

            // add explosion force to all players within the blast radius
            foreach (var car in GameObject.FindGameObjectsWithTag("Player"))
            {
                var rb = car.GetComponent <Rigidbody>();
                rb.AddExplosionForce(
                    m_ExplosionForce,
                    m_Ball.transform.position,
                    m_BlastRadius);
            }

            m_GoalScoredEvent.Invoke(m_GoalColor);
        }
    }