Пример #1
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Paddle"))
        {
            audioSource.Play();
            var maxDist = other.transform.localScale.x * 1f * 0.5f + transform.localScale.x * 1f * 0.5f;
            var dist    = transform.position.x - other.transform.position.x;
            var nDist   = dist / maxDist;

            velocity = new Vector3(nDist * maxX, 0, -velocity.z);
        }
        else if (other.CompareTag("Wall"))
        {
            audioSource.Play();
            velocity = new Vector3(-velocity.x, velocity.y, velocity.z);
        }
        else if (other.CompareTag("TopWall"))
        {
            audioSource.Play();
            velocity = new Vector3(velocity.x, velocity.y, -velocity.z);
        }
        else if (other.CompareTag("BottomWall"))
        {
            transform.position = new Vector3(0, 0, -16);
            velocity           = new Vector3(0, 0, maxZ);

            Paddle paddle = GameObject.Find("Paddle").GetComponent <Paddle>();

            paddle.ResetPlayer();
            paddle.AdaptLive();

            if (paddle.player.lives == 0)
            {
                GameOver(paddle);
            }
        }
        else if (other.CompareTag("Brick"))
        {
            audioSource.Play();
            velocity = new Vector3(velocity.x, velocity.y, -velocity.z);
        }
    }