Example #1
0
    void FixedUpdate()
    {
        float h = 0;

        if (
            Input.GetKey(KeyCode.A) ||
            Input.GetKey(KeyCode.LeftArrow)
            )
        {
            h -= 1.0f;
        }
        if (
            Input.GetKey(KeyCode.D) ||
            Input.GetKey(KeyCode.RightArrow)
            )
        {
            h += 1.0f;
        }

        Debug.Log(h);

        characterMovement.horizontalMovement = h;

        if (Mathf.Abs(h) < Mathf.Epsilon)
        {
            characterMovement.Brake();
        }
    }
Example #2
0
    void FixedUpdate()
    {
        float h = 0;

        if (
            Input.GetKey(KeyCode.A) ||
            Input.GetKey(KeyCode.LeftArrow)
            )
        {
            h -= 1.0f;
        }
        if (
            Input.GetKey(KeyCode.D) ||
            Input.GetKey(KeyCode.RightArrow)
            )
        {
            h += 1.0f;
        }
        if (
            Input.GetKey(KeyCode.S) ||
            Input.GetKey(KeyCode.DownArrow)
            )
        {
            h *= 0.5f;
        }

        var shouldPlayWalkAnim = Mathf.Abs(h) > Mathf.Epsilon;

        robotAnimator.SetBool("shouldWalk", shouldPlayWalkAnim);

        characterMovement.horizontalMovement = h;

        if (Mathf.Abs(h) < Mathf.Epsilon)
        {
            characterMovement.Brake();
        }
    }