Beispiel #1
0
        void GravityGunOff()
        {
            if (!GrabbedBox)
            {
                return;
            }

            GravityGunActive  = false;
            SpriteRend.sprite = NormalSprite;
            GrabbedBox.ToggleGrabbed();

            GrabbedBox = null;
            if (!CanMove)
            {
                CanMove = true;
            }

            rigidBody.gravityScale = 1;

            Debug.Log("Gravity gun off");
        }
Beispiel #2
0
        void GravityGunOn()
        {
            // Check if box is in front of us.
            var boxInRange = Raycast(new Vector2(Direction * 0.5f, 0), Direction * Vector2.right, GravityGunRange, LayersManager.GetLayerMaskObjects(WorldsController.PlayerCurrentWorld));

            if (boxInRange && boxInRange.transform.gameObject.tag == "Box")
            {
                GunNoiseSource?.Play();
                GravityGunActive  = true;
                SpriteRend.sprite = GravityGunSprite;

                // Grab box, turn off its colliders, save its position relative to player, expand player collider
                GrabbedBox = boxInRange.transform.gameObject.GetComponent <BoxController>();
                GrabbedBox.ToggleGrabbed();
                BoxHitbox = GrabbedBox.gameObject.GetComponent <BoxCollider2D>();

                if (GrabbedBox.transform.position.x - gameObject.transform.position.x < 0)
                {
                    BoxOffset = new Vector2(GrabbedBox.transform.position.x - gameObject.transform.position.x - MinDistance, GrabbedBox.transform.position.y - gameObject.transform.position.y);
                }
                else
                {
                    BoxOffset = new Vector2(GrabbedBox.transform.position.x - gameObject.transform.position.x + MinDistance, GrabbedBox.transform.position.y - gameObject.transform.position.y);
                }

                // If player grabs a box but isn't on the ground OR has something over it, they can't pull it
                if (!IsGrounded && GrabbedBox.IsGrounded)
                {
                    rigidBody.velocity     = new Vector2(0, 0);
                    rigidBody.gravityScale = 0;
                    CanMove = false;
                }
                if (!GrabbedBox.IsGrabbable)
                {
                    CanMove = false;
                }

                Debug.Log("Gravity gun on");
            }
        }