Example #1
0
    void handleInput()
    {
        // face player towards mouse
        var localScale = spriteRenderer.transform.localScale;

        if (remote.angle > 90 || remote.angle < -90)
        {
            localScale.x = scaleX * -1;
        }
        else
        {
            localScale.x = scaleX;
        }

        // play whoosh sound if player changes direction
        if (localScale != spriteRenderer.transform.localScale)
        {
            GM.instance.audioManager.PlaySound("Whoosh");
        }
        spriteRenderer.transform.localScale = localScale;


        // pause and unpause
        // if(Input.GetKeyDown(KeyCode.P)){
        //     GM.instance.TogglePause();
        // }

        // menu
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            GM.instance.GoToMenu();
        }


        // restart
        if (Input.GetKeyDown(KeyCode.R))
        {
            GM.instance.RestartLevel();
        }

        if (isDead)
        {
            return;
        }

        // Remote action button
        if (Input.GetMouseButtonDown(0))
        {
            remote.Click();
        }

        if (isAttracted)
        {
            return;
        }

        /*
         *  You can't do anything below here if the player is being
         *  attracted (by a tv or whatever else I code in)
         */

        // basic motion, movement is frozen while jumping
        if (!isJumping && !isAttracted)
        {
            float horizontal = Input.GetAxisRaw("Horizontal");
            float vertical   = Input.GetAxisRaw("Vertical");
            var   motion     = new Vector2(horizontal, vertical);
            mover.Move(motion);
        }
        animator.SetBool("moving", mover.moving);

        // player can only jump while running, also you can't jump while jumping
        if ((Input.GetMouseButtonDown(1) || Input.GetKeyDown(KeyCode.LeftShift)) &&
            !isJumping)
        {
            print("Jumping");
            isJumping = true;
            animator.SetBool("jumping", isJumping);
            animator.Play("Jump");
            GM.instance.audioManager.PlaySound("Jump");

            // disable collisions with objects only
            Physics2D.IgnoreLayerCollision(gameObject.layer, obstacleLayer);
            Physics2D.IgnoreLayerCollision(gameObject.layer, tvLayer);
            // spawn dust
            spawnDust();
        }
    }