Exemple #1
0
 public void MenuContinueGame()
 {
     Debug.Log("Continue");
     pauseAnims.SetTrigger("ClosePause");
     cursorControlScript.ContinueGame();
 }
Exemple #2
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (cursorControlScript.isPaused == false && Time.timeScale == 1)
            {
                PauseScript.OpenMenu();
                cursorControlScript.PauseGame();
            }
            else if (Time.timeScale == 0)
            {
                PauseScript.MenuContinueGame();
                cursorControlScript.ContinueGame();
            }
        }

        if (currentState == PlayerState.DYING)
        {
            anim.SetBool("isDead", true);
            Time.timeScale = Mathf.Lerp(Time.timeScale, 0, 10 * Time.unscaledDeltaTime);
            if (Input.anyKeyDown)
            {
                Instantiate(deadFucker, gameObject.transform.position, gameObject.transform.rotation);
                gameObject.transform.position = currentCheckpoint.transform.position;
                cursorControlScript.ContinueGame();
                KillAll();
            }
            return;
        }
        else
        {
            anim.SetBool("isDead", false);
        }

        //Setting up variables for moving the player later based on inputs
        var xIntent = rb.velocity.x;
        var yIntent = rb.velocity.y;

        if (Input.GetKeyDown(KeyCode.R))
        {
            KillAll();
        }

        if (currentState == PlayerState.GROUNDED)
        {
            xIntent = 0;
            //Taking inputs for LR player movement intent
            if (Input.GetKey(right))
            {
                xIntent += 20;
            }
            if (Input.GetKey(left))
            {
                xIntent -= 20;
            }

            //Taking inputs for the player's jump
            {
                if (Input.GetKey(jump))
                {
                    yIntent = 30;
                }
            }

            anim.SetBool("grounded", true);
        }
        else
        {
            anim.SetBool("grounded", false);
        }

        if (currentState == PlayerState.AIRBORNE)
        {
            rb.gravityScale = 5;
            //Taking inputs for LR player movement intent
            if (Input.GetKey(right) && rb.velocity.x < aerialSpeedCap)
            {
                xIntent += 0.5f;
            }
            if (Input.GetKey(left) && rb.velocity.x > -aerialSpeedCap)
            {
                xIntent -= 0.5f;
            }

            //Artificial Friction
            if (rb.velocity.x > aerialSpeedCap)
            {
                xIntent -= 1;
            }
            if (rb.velocity.x < -aerialSpeedCap)
            {
                xIntent += 1;
            }
            if (rb.velocity.y > aerialSpeedCap)
            {
                yIntent -= 0.5f;
            }
        }

        if (currentState == PlayerState.SWING)
        {
            if (Input.GetKey(right))
            {
                rPressed = true;
            }
            else
            {
                rPressed = false;
            }
            if (Input.GetKey(left))
            {
                lPressed = true;
            }
            else
            {
                lPressed = false;
            }
        }

        if (xIntent != 0)
        {
            if (rb.velocity.x < 0)
            {
                animSprite.localScale = new Vector3(-1, 1, 1);
            }
            if (rb.velocity.x > 0)
            {
                animSprite.localScale = new Vector3(1, 1, 1);
            }
            anim.SetBool("isWalking", true);
        }
        else
        {
            anim.SetBool("isWalking", false);
        }
        if (rb.velocity.y > 0)
        {
            anim.SetBool("movingUp", true);
        }
        if (rb.velocity.y < 0)
        {
            anim.SetBool("movingUp", false);
        }
        currentVelocity = rb.velocity.magnitude;

        //Actually moving the player
        wantedDirection = new Vector2(xIntent, yIntent);
        rb.velocity     = wantedDirection;


        //Hook Controls
        if (currentState == PlayerState.GROUNDED && Time.timeScale == 1 || currentState == PlayerState.AIRBORNE && Time.timeScale == 1)
        {
            //Through
            if (Input.GetMouseButtonDown(0) && hookControlScript.CanHook())
            {
                hookControlScript.DestinationSetter();
                currentState = PlayerState.HOOK;
                goingThrough = true;
            }
            //To
            if (Input.GetMouseButtonDown(2) && hookControlScript.CanHook())
            {
                hookControlScript.DestinationSetter();
                currentState = PlayerState.HOOK;
                goingThrough = false;
            }
        }

        //Running the script for Hooking and Swinging code
        if (currentState == PlayerState.HOOK)
        {
            rb.gravityScale = 0;
            hookControlScript.MoveThrough();
        }
        if (currentState == PlayerState.SWING)
        {
            rb.gravityScale = 0;
            hookControlScript.Swing();
        }
    }