Example #1
0
    void Update()
    {
        // The player is grounded if a linecast to the groundcheck position hits anything on the ground layer.
        grounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground"));
        walled   = Physics2D.Linecast(transform.position, wallCheck.position, 1 << LayerMask.NameToLayer("Wall"));

        Debug.Log("I am grounded " + grounded);
        Debug.Log("I am walled " + walled);

        // If the jump button is pressed and the player is grounded then the player should jump.
        if (Input.GetButtonDown("Jump") && grounded && !walled)
        {
            jump = true;
        }

        if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift))
        {
            gearMeter.ShiftGear(1);
        }

        if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl))
        {
            gearMeter.ShiftGear(0);
        }

        if (charging)
        {
            gearMeter.GainEnergy();
        }
        else
        {
            gearMeter.LoseEnergy();
        }
    }
Example #2
0
    void Update()
    {
        switch (dashState)
        {
        case DashState.Ready:
            anim.SetBool("isDash", true);
            var isDashKeyDown = Input.GetKeyDown(KeyCode.LeftAlt);
            if (isDashKeyDown && gearMeter.gear == 3)
            {
                GetComponent <PlayerControl>().maxSpeed *= 2f;
                savedVelocity = GetComponent <Rigidbody2D>().velocity;
                GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x * 3f, GetComponent <Rigidbody2D>().velocity.y);
                gearMeter.LoseEnergy(dashCost);
                dashState = DashState.Dashing;
            }
            break;

        case DashState.Dashing:

            anim.SetBool("isDash", true);
            dashTimer += Time.deltaTime * 3;
            if (dashTimer >= maxDash)
            {
                dashTimer = maxDash;
                GetComponent <Rigidbody2D>().velocity = savedVelocity;
                dashState = DashState.Cooldown;
            }
            break;

        case DashState.Cooldown:
            anim.SetBool("isDash", false);
            GetComponent <PlayerControl>().maxSpeed = 5f;
            dashTimer -= Time.deltaTime;
            if (dashTimer <= 0)
            {
                dashTimer = 0;
                dashState = DashState.Ready;
            }
            break;
        }
    }