예제 #1
0
    private void CollisionEnter(Collider2D collider, CollisionSide side)
    {
        if (collider.CompareTag("Wall"))
        {
            BounceOffSide(side);
            //VFXManager.SpawnParticleOneshot(VFXManager.instance.ballBounceVFX,(Vector2)transform.position + GetDirFromSide(side) * wallCollider.bounds.extents.x);
        }
        else if (collider.CompareTag("Player"))
        {
            lastPriorityBounceTime = Time.time;

            BounceOffSide(CollisionSide.below);

            if (side == CollisionSide.below)
            {
                float vausSpd = vaus.GetPositionXDifference();

                float spinValue = Mathf.Lerp(0, maxSpin, Mathf.Abs(vausSpd) / LevelManager.playArea.width) * Mathf.Sign(vausSpd);

                SetSpin(spinValue);
            }

            VFXManager.SpawnParticleOneshot(VFXManager.instance.ballBounceVFX,
                                            (Vector2)transform.position + GetDirFromSide(side) * wallCollider.bounds.extents.x);
        }
        else
        {
            BounceOffSide(side);
            BaseBlock block = collider.GetComponent <BaseBlock>();
            if (block != null)
            {
                lastPriorityBounceTime = Time.time;

                VFXManager.SpawnParticleOneshot(VFXManager.instance.blockDamagedVFX,
                                                (Vector2)transform.position + GetDirFromSide(side) * wallCollider.bounds.extents.x);
                block.OnHit();
            }
            else
            {
                Debug.LogError("Bounced off unidentified object!");
                VFXManager.SpawnParticleOneshot(VFXManager.instance.ballBounceVFX, (Vector2)transform.position + GetDirFromSide(side) * wallCollider.bounds.extents.x);
            }
        }
    }