Esempio n. 1
0
    private void OnCollisionEnter2D(Collision2D other)
    {
        GameObject collisionObject = other.gameObject;

        if (myTrailRenderer.enabled)
        {
            myTrailRenderer.enabled = false;
        }
        switch (collisionObject.tag)
        {
        case "Border":
        {
            GameManager.Instance.MyMatchManager.AddPointTo(lastPlayerHitting.GetOpponent());
            lastPlayerHitting = lastPlayerHitting.GetOpponent();
            break;
        }

        case "Ground":
        {
            if ((lastPlayerHitting == playerNumber.Player1 && transform.position.x > 0) ||
                (lastPlayerHitting == playerNumber.Player2 && transform.position.x < 0))
            {
                GameManager.Instance.MyMatchManager.AddPointTo(lastPlayerHitting);
            }
            else
            {
                GameManager.Instance.MyMatchManager.AddPointTo(lastPlayerHitting.GetOpponent());
                lastPlayerHitting = lastPlayerHitting.GetOpponent();
            }

            break;
        }

        case "Net":
        {
            GameManager.Instance.MyMatchManager.AddPointTo(lastPlayerHitting.GetOpponent());
            lastPlayerHitting = lastPlayerHitting.GetOpponent();
            break;
        }

        case "Player":
        {
            //TODO rewrite those 3 lines (yes the sound of hittingplayer is way too strong)
            myAudioSource.volume /= 5;
            myAudioSource.PlayOneShot(hitPlayerSound);
            myAudioSource.volume *= 5;
            PlayerMove player = collisionObject.GetComponent <PlayerMove>();
            GameManager.Instance.MyMatchManager.AddPointTo(player.PlayerNumber.GetOpponent());
            lastPlayerHitting = player.PlayerNumber.GetOpponent();
            break;
        }
        }
    }
Esempio n. 2
0
 public void AddPointTo(playerNumber player)
 {
     myAudioSource.PlayOneShot(pointSound);
     GameManager.Instance.Score[player]++;
     GameManager.Instance.UpdateUI();
     Engage(player.GetOpponent());
 }