Beispiel #1
0
    // Update sprite set to match current health
    private void UpdateAnimation()
    {
        if (mAttackState == AttackState.Idle && mMovementState == MovementState.Idle)
        {
            mUnitAnimator.Idle();
            return;
        }

        Vector3 direction;

        if (mAttackTarget != null)
        {
            direction = mAttackTarget.Position - this.Position;
        }
        else
        {
            direction = mDestination - this.Position;
        }

        if (mAttackState == AttackState.Idle || mAttackState == AttackState.Engaging)
        {
            if (direction.x >= 0)
            {
                mUnitAnimator.WalkRight();
            }
            else
            {
                mUnitAnimator.WalkLeft();
            }
        }
        else
        {
            if (direction.x >= 0)
            {
                mUnitAnimator.AttackRight();
            }
            else
            {
                mUnitAnimator.AttackLeft();
            }
        }

        int sortingOrder = (int)(4 * (-Position.y + Camera.main.orthographicSize));

        GetComponent <SpriteRenderer> ().sortingOrder = (int)(sortingOrder);
    }