예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (GameManager.instance.CurrentGameState == GameManager.GameState.paused)
        {
            return;
        }

        if (isObjectAttached && attachedObject == null)
        {
            isObjectAttached = false;
            player.SetHolding(false);
            player.SetAimNothing();
        }

        if (isObjectAttached && attachedObject != null)
        {
            if (!attachedObject.isAttachedPlayer)
            {
                releaseAttachedObject();
                player.SetAimNothing();
            }
            else
            {
                attachedObject.transform.parent.position = player.CatchPos.position;
                player.SetHolding(true);
                player.SetAimForward(true);
            }
        }

        SurfaceStick();

        if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift))
        {
            FindObjectOfType <AudioHandler>().Play("Magnet Switch");
            pull = !pull;
            magnetAnim.SetBool("isPushing", !pull);
            if (!pull)
            {
                magBeamRenderer.size = Vector2.zero;
            }
            //Switch push/pull state
        }

        if (Input.GetMouseButtonDown(0) && isObjectAttached)
        {
            if (!pull)
            {
                MagneticObject temp = attachedObject;
                releaseAttachedObject();
                Vector2 lMousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                temp.shootTowards(lMousePos, player.PushMagnitude * 1.5f);
                player.SetPush(true);
                CameraControl.instance.Shake(0.08f, 5, 8f);
                FindObjectOfType <AudioHandler>().Play("Magnet Push");
                CreatePushEffect();
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            player.pullStartBonus = true;
            HandleSetTarget();
        }

        if (Input.GetMouseButton(0))
        {
            if (target != null)
            {
                HandleAttratctionBeam();

                if (target == null)
                {
                    magBeamRenderer.size = Vector2.zero;
                    elapsedPullTime      = 0f;
                }
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            if (target != null)
            {
                switch (target.weight)
                {
                case MagneticObject.MagneticWeight.heavy:
                    player.realseExternalForce();
                    break;

                case MagneticObject.MagneticWeight.light:
                    target.releaseExternalForce();
                    player.stopChannel();
                    break;

                case MagneticObject.MagneticWeight.stop:
                    target.releaseExternalForce();
                    player.stopChannel();
                    break;
                }
                target = null;
            }
            if (!attachedObject)
            {
                player.SetAimNothing();
            }

            magBeamRenderer.size = Vector2.up * magBeamHeight;
            elapsedPullTime      = 0f;
            distToTarget         = 0f;
        }
    }
예제 #2
0
    private void HandleSetTarget(bool useMouseCast = true, RaycastHit2D aHit = new RaycastHit2D())
    {
        RaycastHit2D hit = (useMouseCast) ? Physics2D.Raycast(transform.position, Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position, 100f, magnetLayers) : aHit;

        if (hit)
        {
            if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Ground"))
            {
                FindObjectOfType <AudioHandler>().Play("Miss Sound");
                CreateMissEffect();
                return;
            }
            target = hit.collider.GetComponent <MagneticObject>();

            if (target == null)
            {
                FindObjectOfType <AudioHandler>().Play("Miss Sound");
                CreateMissEffect();
                return;
            }

            if (target.inPlayerRange == false)
            {
                return;
            }

            hitPoint = hit.point;

            switch (target.weight)
            {
            case MagneticObject.MagneticWeight.heavy:
                if (pull)
                {
                    elapsedPullTime = 0f;
                    CreatePullEffect();
                    CameraControl.instance.Shake(0.08f, 5, 8f);
                    player.PullStartBonus(hit.point);
                }
                else
                {
                    player.pushPlayerFrom(hit.point);
                    CreatePushEffect();
                    FindObjectOfType <AudioHandler>().Play("Magnet Push");
                    CameraControl.instance.Shake(0.08f, 5, 8f);
                    player.SetPush(true);
                    //player.realseExternalForce();
                }
                distToTarget  = Vector2.Distance(transform.position, hitPoint);
                pullStartDist = distToTarget;
                break;

            case MagneticObject.MagneticWeight.light:
                if (!isObjectAttached)
                {
                    if (pull)
                    {
                        elapsedPullTime = 0f;
                        CreatePullEffect();
                        CameraControl.instance.Shake(0.08f, 5, 8f);
                    }
                    else
                    {
                        if (isObjectAttached)
                        {
                            target = null; break;
                        }
                        target.shootTowards(hit.point, -player.PushMagnitude);
                        CreatePushEffect();
                        FindObjectOfType <AudioHandler>().Play("Magnet Push");
                        CameraControl.instance.Shake(0.08f, 5, 8f);
                        player.SetPush(true);
                    }
                    distToTarget  = Vector2.Distance(transform.position, hitPoint);
                    pullStartDist = distToTarget;
                }
                break;

            case MagneticObject.MagneticWeight.stop:
                if (!pull)
                {
                    target.transform.parent.GetComponent <ShotgunProjectile>().Stop();
                    CreatePushEffect();
                    FindObjectOfType <AudioHandler>().Play("Magnet Push");
                    CameraControl.instance.Shake(0.08f, 5, 8f);
                    player.SetPush(true);
                }
                break;
            }
        }
    }