Пример #1
0
    void Awake()
    {
        sprite         = transform.GetChild(0).gameObject;
        spriteRenderer = sprite.GetComponent <SpriteRenderer>();
        animator       = sprite.GetComponent <SpriteAnim>();

        this.animations = new Dictionary <PlayerAnim, AnimationClip>();
        for (int i = 0; i < animHookup.Length; i++)
        {
            animations[animHookup[i].ID] = animHookup[i].animation;
        }

        this.originalJumpSpeed = this.jumpSpeed;

        respawnPos = this.transform.position;

        fsm = new StateMachine <PlayerState>(PlayerState.Air);
        fsm.Bind(PlayerState.Air, null, Air_Update, null);
        fsm.Bind(PlayerState.Ground, Ground_Enter, Ground_Update, Ground_Exit);
        fsm.Bind(PlayerState.Throwing, Throwing_Enter, Throwing_Update, Throwing_Exit);
        fsm.Bind(PlayerState.Pickup, Pickup_Enter, Pickup_Update, Pickup_Exit);
        fsm.onChangeState += (newState) => {
            if (fsm.currentState == PlayerState.Air && newState == PlayerState.Ground)
            {
                SfxManager.PlaySoundStatic(SoundType.LAND);
            }
        };
        currentSpeed = speed;
    }