예제 #1
0
    // Update is called once per frame
    void Update()
    {
        UnitState = UnitState.NAND(Enums.UnitStateEnum.Moving);

        // Apply landing
        if (UnitState.HasFlag(Enums.UnitStateEnum.Landing))
        {
            UnitState |= Enums.UnitStateEnum.Grounded;
            UnitState  = UnitState.NAND(Enums.UnitStateEnum.Landing);
        }

        // Zero vertical velocity when we're on the ground
        if (UnitState.HasFlag(Enums.UnitStateEnum.Grounded))
        {
            rigidBody.velocity = new Vector2(rigidBody.velocity.x, 0);
        }

        TakeAction();

        MotionDamping();

        UpdateUnitState();

        var scale = new Vector3(Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z);

        if (UnitState.HasFlag(Enums.UnitStateEnum.FacingLeft))
        {
            scale.x *= -1;
        }
        transform.localScale = scale;

        UpdateAnimations();
    }
예제 #2
0
    private void UpdateUnitState()
    {
        if (rigidBody.velocity.y < 0)
        {
            UnitState |= Enums.UnitStateEnum.Falling;
            UnitState  = UnitState.NAND(Enums.UnitStateEnum.Jumping);
        }
        else if (rigidBody.velocity.y >= 0)
        {
            UnitState |= Enums.UnitStateEnum.Jumping;
            UnitState  = UnitState.NAND(Enums.UnitStateEnum.Falling);
        }

        if (UnitState.HasFlag(Enums.UnitStateEnum.Grounded) && !UnitState.HasFlag(Enums.UnitStateEnum.Falling))
        {
            UnitState = UnitState.NAND(Enums.UnitStateEnum.Jumping);
            UnitState = UnitState.NAND(Enums.UnitStateEnum.DoubleJumping);
        }

        if (rigidBody.velocity.x > 0 && UnitState.HasFlag(Enums.UnitStateEnum.Moving))
        {
            UnitState |= Enums.UnitStateEnum.FacingRight;
            UnitState  = UnitState.NAND(Enums.UnitStateEnum.FacingLeft);
        }
        else if (rigidBody.velocity.x < 0 && UnitState.HasFlag(Enums.UnitStateEnum.Moving))
        {
            UnitState |= Enums.UnitStateEnum.FacingLeft;
            UnitState  = UnitState.NAND(Enums.UnitStateEnum.FacingRight);
        }
    }