private void Update()
    {
        // Animation
        // Determine target animation.

        Vector2 _temp = new Vector2(teddy.transform.position.x, gameObject.transform.position.y);

        gameObject.transform.position = _temp;

        if (teddyView.input.x == 0)
        {
            targetAnimation = idle;
        }
        else
        {
            targetAnimation = walk;
        }



        // Handle change in target animation.
        if (previousTargetAnimation != targetAnimation)
        {
            Spine.Animation transition = null;

            skeletonAnimation.AnimationState.SetAnimation(0, targetAnimation, true);
        }
        previousTargetAnimation = targetAnimation;

        // Face intended direction.
        if (teddyView.input.x != 0)
        {
            skeletonAnimation.Skeleton.FlipX = teddyView.input.x > 0;
        }
    }
Пример #2
0
 //sets character animation
 public void SetAnimation(AnimationReferenceAsset animation, bool loop, float timeScale)
 {
     if (animation.name.Equals(currentAnimation))
     {
         return;
     }
     skeletonAnimation.state.SetAnimation(0, animation, loop).TimeScale = timeScale;
 }
Пример #3
0
 void SetAnimationAsset(AnimationReferenceAsset anim, bool loop, float timeScale)
 {
     if (currentAnimationName == anim.name)
     {
         return;
     }
     mySkeleton.state.SetAnimation(0, anim, loop).TimeScale = timeScale;
     currentAnimationName = anim.name;
 }
Пример #4
0
 public AnimationService(MovementEventRepository movementEventRepository,
                         SkeletonAnimation skeletonAnimation, PlayerMarker player)
 {
     this.movementEventRepository = movementEventRepository ?? throw new ArgumentNullException(nameof(movementEventRepository));
     this.skeletonAnimation       = skeletonAnimation ?? throw new ArgumentNullException(nameof(skeletonAnimation));
     this.idle    = player.idle ?? throw new ArgumentNullException(nameof(idle));
     this.walking = player.walking ?? throw new ArgumentNullException(nameof(walking));
     this.player  = player ?? throw new ArgumentNullException(nameof(player));
 }
Пример #5
0
    public void Setanim(AnimationReferenceAsset anim, bool loop, float timescale)
    {
        if (anim.name.Equals(CurrentState))
        {
            return;
        }
        CurrentState = anim.name;

        skeletonAnimation_Left.state.SetAnimation(0, anim, loop).TimeScale = timescale;
    }
Пример #6
0
        public void PlayAnimation(AnimationReferenceAsset animation, bool loop, float timeScale = 1f)
        {
            if (null == _skeletonAnimation || null == animation)
            {
                return;
            }

            _skeletonAnimation.state.SetAnimation(0, animation, loop).TimeScale     = timeScale;
            _skeletonAnimation.state.AddAnimation(0, _idleAnim, true, 0f).TimeScale = timeScale;
        }
Пример #7
0
 private void SetAnimation(SkeletonAnimation skeletonAnimation, AnimationReferenceAsset animation, bool loop, bool wait, float timeScale)
 {
     if (!wait)
     {
         skeletonAnimation.state.SetAnimation(0, animation, loop).TimeScale = timeScale;
     }
     else
     {
         skeletonAnimation.state.SetAnimation(0, animation, loop).TimeScale = timeScale;
         skeletonAnimation.state.SetAnimation(0, animation, loop).Complete += Test;
     }
 }
Пример #8
0
 public void DIE()
 {
     GameController.instance.NPCDIE();
     if (currentAnim == die)
     {
         sk.ClearState();
         return;
     }
     sk.AnimationState.SetAnimation(0, die, false);
     currentAnim = die;
     Debug.LogError("DIE");
 }
Пример #9
0
 public void AnimWin()
 {
     sk.ClearState();
     if (currentAnim == win)
     {
         return;
     }
     sk.AnimationState.SetAnimation(0, win, true);
     currentAnim  = win;
     rid.velocity = Vector2.zero;
     speedmove    = 0;
 }
Пример #10
0
    public void SetAnimation(AnimationReferenceAsset animation, bool loop, float timeScale)
    {
        if (animation.name.Equals(_currentAnimation))
        {
            return;
        }

        Spine.TrackEntry animationEntry = SkeletonAnimation.state.SetAnimation(0, animation, loop);
        animationEntry.TimeScale = timeScale;
        _currentAnimation        = animation.name;
        animationEntry.Complete += AnimationEntry_Complete;
    }
Пример #11
0
 public virtual void PlayAnim(int indexTrack, AnimationReferenceAsset anim, bool loop)
 {
     if (enemyState == EnemyState.die)
     {
         return;
     }
     if (currentAnim != anim)
     {
         skeletonAnimation.AnimationState.SetAnimation(indexTrack, anim, loop);
         currentAnim = anim;
         //if (anim == aec.standup)
         //    Debug.LogError("zoooo");
     }
 }
Пример #12
0
    private void _AsyncAnimation(AnimationReferenceAsset animCip, bool loop, float timeScale)
    {
        //동일한 애니메이션을 재생하려고 한다면 아래 코드 구문 실행 x
        if (animCip.name.Equals(currentAnimation))
        {
            return;
        }

        //해당 애니메이션으로 변경한다.
        skeletonAnimation.state.SetAnimation(0, animCip, loop).TimeScale = timeScale;
        skeletonAnimation.loop      = loop;
        skeletonAnimation.timeScale = timeScale;

        //현재 재생되고 있는 애니메이션 값을 변경
        currentAnimation = animCip.name;
    }
Пример #13
0
 public virtual void Attack(int indexTrack, AnimationReferenceAsset anim, bool loop, float _maxTimedelayAttack)
 {
     if (enemyState == EnemyState.die)
     {
         return;
     }
     if (Time.time - timePreviousAttack >= _maxTimedelayAttack)
     {
         timePreviousAttack = Time.time;
         skeletonAnimation.AnimationState.SetAnimation(indexTrack, anim, loop);
         if (currentAnim != anim)
         {
             currentAnim = anim;
         }
     }
 }
Пример #14
0
    private void Update()
    {
        // Animation
        // Determine target animation.

        if (input.x == 0)
        {
            targetAnimation = idle;
        }
        else
        {
            targetAnimation = Mathf.Abs(input.x) > 0.3f ? run : walk;
        }



        // Handle change in target animation.
        if (previousTargetAnimation != targetAnimation)
        {
            Spine.Animation transition = null;
            //if (transitions != null && previousTargetAnimation != null)
            //{
            //transition = transitions.GetTransition(previousTargetAnimation, targetAnimation);
            //}

            if (transition != null)
            {
                skeletonAnimation.AnimationState.SetAnimation(0, transition, false).MixDuration = 0.05f;
                skeletonAnimation.AnimationState.AddAnimation(0, targetAnimation, true, 0f);
            }
            else
            {
                skeletonAnimation.AnimationState.SetAnimation(0, targetAnimation, true);
            }
        }
        previousTargetAnimation = targetAnimation;

        // Face intended direction.
        if (input.x != 0)
        {
            skeletonAnimation.Skeleton.FlipX = input.x > 0;
        }
    }
Пример #15
0
    private IEnumerator JumpTemp()
    {
        float timeUp = timeJump * 0.5f;

        if (currentAnim != jump)
        {
            sk.AnimationState.SetAnimation(0, jump, true);
            currentAnim = jump;
            for (float t = 0; t <= timeUp; t += Time.deltaTime)
            {
                force = forceJump * (timeUp - t);
                //  jumpVelo = rid.velocity;
                jumpVelo.x   = rid.velocity.x;
                jumpVelo.y   = force;
                rid.velocity = jumpVelo;
                yield return(null);
            }
        }
    }
Пример #16
0
    public void Init(string name, string text, SkeletonDataAsset skeletonDataAsset, AnimationReferenceAsset animation, Color backColor)
    {
        if (!string.IsNullOrEmpty(name) && nameTextField)
        {
            nameTextField.text = name;
        }

        textTextField.text = text;

        if (avatar)
        {
            avatar.gameObject?.SetActive(false);
        }

        back.color = backColor;

        spineParent.gameObject.SetActive(true);
        spineSkeleton.Clear();
        spineSkeleton.skeletonDataAsset = skeletonDataAsset;
        spineSkeleton.Initialize(true);
        spineSkeleton.AnimationState.SetAnimation(0, animation, true);
    }
        private void PlayNewStableAnimation()
        {
            Spine.Animation        jump;
            SpineBeginnerBodyState state = this.model.state;

            if ((this.previousViewState == SpineBeginnerBodyState.Jumping) && (state != SpineBeginnerBodyState.Jumping))
            {
                this.PlayFootstepSound();
            }
            if (state == SpineBeginnerBodyState.Jumping)
            {
                this.jumpSource.Play();
                jump = (Spine.Animation) this.jump;
            }
            else if (state == SpineBeginnerBodyState.Running)
            {
                jump = (Spine.Animation) this.run;
            }
            else
            {
                jump = (Spine.Animation) this.idle;
            }
            this.skeletonAnimation.AnimationState.SetAnimation(0, jump, true);
        }
Пример #18
0
 public void SetAnimation(AnimationReferenceAsset animation, bool loop, float timeScale)
 {
     skeletonAnimation.state.SetAnimation(0, animation, loop).TimeScale = timeScale;
 }
Пример #19
0
        private void Update()
        {
            float deltaTime  = Time.deltaTime;
            bool  isGrounded = this.controller.isGrounded;
            bool  flag2      = !this.wasGrounded && isGrounded;

            this.input.x = Input.GetAxis(this.XAxis);
            this.input.y = Input.GetAxis(this.YAxis);
            bool buttonUp   = Input.GetButtonUp(this.JumpButton);
            bool buttonDown = Input.GetButtonDown(this.JumpButton);
            bool flag5      = (isGrounded && (this.input.y < -0.5f)) || (this.forceCrouchEndTime > Time.time);
            bool flag6      = false;
            bool flag7      = false;
            bool flag8      = false;

            if (flag2 && (-this.velocity.y > this.forceCrouchVelocity))
            {
                flag8 = true;
                flag5 = true;
                this.forceCrouchEndTime = Time.time + this.forceCrouchDuration;
            }
            if (!flag5)
            {
                if (isGrounded)
                {
                    if (buttonDown)
                    {
                        flag7 = true;
                    }
                }
                else
                {
                    flag6 = buttonUp && (Time.time < this.minimumJumpEndTime);
                }
            }
            Vector3 vector = (Physics.gravity * this.gravityScale) * deltaTime;

            if (flag7)
            {
                this.velocity.y         = this.jumpSpeed;
                this.minimumJumpEndTime = Time.time + this.minimumJumpDuration;
            }
            else if (flag6 && (this.velocity.y > 0f))
            {
                this.velocity.y *= this.jumpInterruptFactor;
            }
            this.velocity.x = 0f;
            if (!flag5 && (this.input.x != 0f))
            {
                this.velocity.x  = (Mathf.Abs(this.input.x) <= 0.6f) ? this.walkSpeed : this.runSpeed;
                this.velocity.x *= Mathf.Sign(this.input.x);
            }
            if (!isGrounded)
            {
                if (this.wasGrounded)
                {
                    if (this.velocity.y < 0f)
                    {
                        this.velocity.y = 0f;
                    }
                }
                else
                {
                    this.velocity += vector;
                }
            }
            this.controller.Move(this.velocity * deltaTime);
            if (isGrounded)
            {
                if (flag5)
                {
                    this.targetAnimation = this.crouch;
                }
                else if (this.input.x == 0f)
                {
                    this.targetAnimation = this.idle;
                }
                else
                {
                    this.targetAnimation = (Mathf.Abs(this.input.x) <= 0.6f) ? this.walk : this.run;
                }
            }
            else
            {
                this.targetAnimation = (this.velocity.y <= 0f) ? this.fall : this.jump;
            }
            if (this.previousTargetAnimation != this.targetAnimation)
            {
                Spine.Animation transition = null;
                if ((this.transitions != null) && (this.previousTargetAnimation != null))
                {
                    transition = this.transitions.GetTransition((Spine.Animation) this.previousTargetAnimation, (Spine.Animation) this.targetAnimation);
                }
                if (transition != null)
                {
                    this.skeletonAnimation.AnimationState.SetAnimation(0, transition, false).MixDuration = 0.05f;
                    this.skeletonAnimation.AnimationState.AddAnimation(0, (Spine.Animation) this.targetAnimation, true, 0f);
                }
                else
                {
                    this.skeletonAnimation.AnimationState.SetAnimation(0, (Spine.Animation) this.targetAnimation, true);
                }
            }
            this.previousTargetAnimation = this.targetAnimation;
            if (this.input.x != 0f)
            {
                this.skeletonAnimation.Skeleton.FlipX = this.input.x < 0f;
            }
            if (flag7)
            {
                this.jumpAudioSource.Stop();
                this.jumpAudioSource.Play();
            }
            if (flag2)
            {
                if (flag8)
                {
                    this.hardfallAudioSource.Play();
                }
                else
                {
                    this.footstepHandler.Play();
                }
                this.landParticles.Emit((int)(((int)(this.velocity.y / -9f)) + 2));
            }
            this.wasGrounded = isGrounded;
        }
Пример #20
0
        void Update()
        {
            float dt         = Time.deltaTime;
            bool  isGrounded = controller.isGrounded;
            bool  landed     = !wasGrounded && isGrounded;

            // Dummy input.
            input.x = Input.GetAxis(XAxis);
            input.y = Input.GetAxis(YAxis);
            bool inputJumpStop   = Input.GetButtonUp(JumpButton);
            bool inputJumpStart  = Input.GetButtonDown(JumpButton);
            bool doCrouch        = (isGrounded && input.y < -0.5f) || (forceCrouchEndTime > Time.time);
            bool doJumpInterrupt = false;
            bool doJump          = false;
            bool hardLand        = false;

            if (landed)
            {
                if (-velocity.y > forceCrouchVelocity)
                {
                    hardLand           = true;
                    doCrouch           = true;
                    forceCrouchEndTime = Time.time + forceCrouchDuration;
                }
            }

            if (!doCrouch)
            {
                if (isGrounded)
                {
                    if (inputJumpStart)
                    {
                        doJump = true;
                    }
                }
                else
                {
                    doJumpInterrupt = inputJumpStop && Time.time < minimumJumpEndTime;
                }
            }

            // Dummy physics and controller using UnityEngine.CharacterController.
            Vector3 gravityDeltaVelocity = Physics.gravity * gravityScale * dt;


            if (doJump)
            {
                velocity.y         = jumpSpeed;
                minimumJumpEndTime = Time.time + minimumJumpDuration;
            }
            else if (doJumpInterrupt)
            {
                if (velocity.y > 0)
                {
                    velocity.y *= jumpInterruptFactor;
                }
            }

            velocity.x = 0;
            if (!doCrouch)
            {
                if (input.x != 0)
                {
                    velocity.x  = Mathf.Abs(input.x) > 0.6f ? runSpeed : walkSpeed;
                    velocity.x *= Mathf.Sign(input.x);
                }
            }


            if (!isGrounded)
            {
                if (wasGrounded)
                {
                    if (velocity.y < 0)
                    {
                        velocity.y = 0;
                    }
                }
                else
                {
                    velocity += gravityDeltaVelocity;
                }
            }
            controller.Move(velocity * dt);

            // Animation
            // Determine target animation.
            if (isGrounded)
            {
                if (doCrouch)
                {
                    targetAnimation = crouch;
                }
                else
                {
                    if (input.x == 0)
                    {
                        targetAnimation = idle;
                    }
                    else
                    {
                        targetAnimation = Mathf.Abs(input.x) > 0.6f ? run : walk;
                    }
                }
            }
            else
            {
                targetAnimation = velocity.y > 0 ? jump : fall;
            }

            // Handle change in target animation.
            if (previousTargetAnimation != targetAnimation)
            {
                Animation transition = null;
                if (transitions != null && previousTargetAnimation != null)
                {
                    transition = transitions.GetTransition(previousTargetAnimation, targetAnimation);
                }

                if (transition != null)
                {
                    skeletonAnimation.AnimationState.SetAnimation(0, transition, false).MixDuration = 0.05f;
                    skeletonAnimation.AnimationState.AddAnimation(0, targetAnimation, true, 0f);
                }
                else
                {
                    skeletonAnimation.AnimationState.SetAnimation(0, targetAnimation, true);
                }
            }
            previousTargetAnimation = targetAnimation;

            // Face intended direction.
            if (input.x != 0)
            {
                skeletonAnimation.Skeleton.ScaleX = Mathf.Sign(input.x);
            }


            // Effects
            if (doJump)
            {
                jumpAudioSource.Stop();
                jumpAudioSource.Play();
            }

            if (landed)
            {
                if (hardLand)
                {
                    hardfallAudioSource.Play();
                }
                else
                {
                    footstepHandler.Play();
                }

                landParticles.Emit((int)(velocity.y / -9f) + 2);
            }

            wasGrounded = isGrounded;
        }
Пример #21
0
 public override void PlayAnim(int indexTrack, AnimationReferenceAsset anim, bool loop)
 {
     base.PlayAnim(indexTrack, anim, loop);
     canAttack = false;
 }
Пример #22
0
 public void PlayAnim(int index, AnimationReferenceAsset _anim)
 {
     skeletonAnimation.AnimationState.SetAnimation(index, _anim, false);
 }
Пример #23
0
 public AnimationService(SkeletonAnimation skeletonAnimation, NpcMarker npc)
 {
     this.skeletonAnimation = skeletonAnimation ?? throw new ArgumentNullException(nameof(skeletonAnimation));
     this.idle = npc.idle ?? throw new ArgumentNullException(nameof(idle));
     this.npc  = npc ?? throw new ArgumentNullException(nameof(npc));
 }
    private void Update()
    {
        // Animation
        // Determine target animation.

        if (isKicking)
        {
            targetAnimation                     = kick;
            skeletonAnimation.timeScale         = 1;
            skeletonAnimation.skeletonDataAsset = kickSkeletonData;
        }

        else if (input.magnitude == 0)
        {
            targetAnimation                     = idle;
            skeletonAnimation.timeScale         = 1;
            skeletonAnimation.skeletonDataAsset = frontSkeletonData;
        }
        else if (input.y > 0)
        {
            targetAnimation                     = walkBack;
            skeletonAnimation.timeScale         = walkAnimationSpeed;
            skeletonAnimation.skeletonDataAsset = backSkeletonData;
            //skeletonAnimation.skeleton.up
        }
        else
        {
            targetAnimation                     = walkFront;
            skeletonAnimation.timeScale         = walkAnimationSpeed;
            skeletonAnimation.skeletonDataAsset = frontSkeletonData;
        }



        // Handle change in target animation.
        if (previousTargetAnimation != targetAnimation)
        {
            skeletonAnimation.ClearState();
            skeletonAnimation.Initialize(true);
            Spine.Animation transition = null;
            //if (transitions != null && previousTargetAnimation != null)
            //{
            //transition = transitions.GetTransition(previousTargetAnimation, targetAnimation);
            //}

            if (transition != null)
            {
                skeletonAnimation.AnimationState.SetAnimation(0, transition, false).MixDuration = 0.05f;
                skeletonAnimation.AnimationState.AddAnimation(0, targetAnimation, true, 0f);
            }
            else
            {
                skeletonAnimation.AnimationState.SetAnimation(0, targetAnimation, true);
            }
        }
        previousTargetAnimation = targetAnimation;

        // Face intended direction.
        if (input.x != 0)
        {
            skeletonAnimation.Skeleton.FlipX = input.x > 0;
        }

        skeletonAnimation.state.Complete += delegate
        {
            if (isKicking)
            {
                isKicking = false;
                safeScreenModell.KickBox();
            }
        };
    }
    void Update()
    {
        float dt         = Time.deltaTime;
        bool  isGrounded = controller.isGrounded;
        bool  landed     = !wasGrounded && isGrounded;

        // Dummy input.
        input.x = Input.GetAxis(XAxis) + mobileInput.x;
        input.y = Input.GetAxis(YAxis) + mobileInput.y;
        bool inputJumpStop   = Input.GetButtonUp(JumpButton);
        bool inputJumpStart  = Input.GetButtonDown(JumpButton);
        bool doCrouch        = (isGrounded && input.y < -0.5f) || (forceCrouchEndTime > Time.time);
        bool doJumpInterrupt = false;
        bool doJump          = false;
        bool hardLand        = false;

        /*
         * if (landed)
         * {
         *   if (-velocity.y > forceCrouchVelocity)
         *   {
         *       hardLand = true;
         *       doCrouch = true;
         *       forceCrouchEndTime = Time.time + forceCrouchDuration;
         *   }
         * }
         */

        if (!doCrouch)
        {
            if (isGrounded)
            {
                if (inputJumpStart | mobileJumpStart)
                {
                    doJump         = true;
                    mobileJumpStop = false;
                }
            }
            else
            {
                doJumpInterrupt = (inputJumpStop && Time.time < minimumJumpEndTime) || (mobileJumpStop && Time.time < minimumJumpEndTime);
            }
        }

        // Dummy physics and controller using UnityEngine.CharacterController.
        Vector3 gravityDeltaVelocity = Physics.gravity * gravityScale * dt;


        if (doJump)
        {
            velocity.y         = jumpSpeed;
            minimumJumpEndTime = Time.time + minimumJumpDuration;
        }
        else if (doJumpInterrupt)
        {
            if (velocity.y > 0)
            {
                velocity.y *= jumpInterruptFactor;
            }
        }

        velocity.x = 0;
        if (!doCrouch)
        {
            if (input.x != 0)
            {
                velocity.x  = Mathf.Abs(input.x);
                velocity.x *= Mathf.Sign(input.x) * runSpeed;
            }
        }


        if (!isGrounded)
        {
            if (wasGrounded)
            {
                if (velocity.y < 0)
                {
                    velocity.y = 0;
                }
            }
            else
            {
                velocity += gravityDeltaVelocity;
            }
        }
        controller.Move(velocity * dt);

        // Animation
        if (playerHealth.currentHealth <= 0)
        {
            targetAnimation = lose;
            runSpeed        = 0;

            visuals.localPosition = Vector2.Lerp(visuals.localPosition, new Vector2(fallBack, 0f), 2 * Time.deltaTime);
        }
        else
        {
            if (isGrounded)
            {
                if (characterSkill.skillActive)
                {
                    targetAnimation = characterSkill.targetAnimation;
                    characterSkill.Activate();
                }
                else
                {
                    targetAnimation = run;
                }
            }
            else
            {
                if (characterSkill.skillActive)
                {
                    targetAnimation = characterSkill.targetAnimation;
                    characterSkill.Activate();
                }
                else
                {
                    targetAnimation = velocity.y > 0 ? jump : fall;
                }
            }
        }

        // Animation transition
        if (previousTargetAnimation != targetAnimation)
        {
            Spine.Animation transition = null;
            if (transitions != null && previousTargetAnimation != null)
            {
                transition = transitions.GetTransition(previousTargetAnimation, targetAnimation);
            }

            if (transition != null)
            {
                skeletonAnimation.AnimationState.SetAnimation(0, transition, false).MixDuration = 0.10f;
                skeletonAnimation.AnimationState.AddAnimation(0, targetAnimation, true, 0f);

                if (!characterSkill.skillActive)
                {
                    characterSkill.Invoke("DelayedDeactivate", characterSkill.skillEndTransition);
                }
            }
            else if (playerHealth.currentHealth <= 0)
            {
                skeletonAnimation.AnimationState.SetAnimation(0, targetAnimation, false);
            }
            else
            {
                skeletonAnimation.AnimationState.SetAnimation(0, targetAnimation, true);
            }
        }
        previousTargetAnimation = targetAnimation;

        // Effects
        if (doJump)
        {
            jumpAudioSource.Stop();
            jumpAudioSource.Play();
        }

        if (landed)
        {
            if (hardLand)
            {
                hardfallAudioSource.Play();
            }
            else
            {
                footstepHandler.Play();
            }

            landParticles.Emit((int)(velocity.y / -9f) + 2);
        }

        wasGrounded = isGrounded;
    }
Пример #26
0
    private void Update()
    {
        if (PlayerController.instance.playerState == PlayerController.PlayerState.Die || GameController.instance.gameState == GameController.GameState.gameover)
        {
            return;
        }

        isGround = Physics2D.OverlapCircle(poitRayGround.transform.position, radius, lm);
        if (du.gameObject.activeSelf)
        {
            if (isGround)
            {
                if (du.AnimationName == "1")
                {
                    du.AnimationState.SetAnimation(0, "2", false);
                    rid.gravityScale = 1;
                }
            }
            return;
        }

        if (transform.position.x < PlayerController.instance.GetTranformXPlayer())
        {
            if (transform.position.x < PlayerController.instance.GetTranformXPlayer() - distance)
            {
                speedmove = PlayerController.instance.speedMoveMax;

                if (transform.position.x < CameraController.instance.bouders[3].transform.position.x - 2)
                {
                    ResetPosRevive();
                }
            }
            else
            {
                speedmove = 0;
            }
        }
        else
        {
            if (transform.position.x > PlayerController.instance.GetTranformXPlayer() + distance)
            {
                speedmove = -PlayerController.instance.speedMoveMax;
            }
            else
            {
                speedmove = 0;
            }
        }

        if (isGround)
        {
            if (rid.velocity.y <= 0)
            {
                if (speedmove != 0)
                {
                    if (speedmove < 0)
                    {
                        if (FlipX)
                        {
                            if (currentAnim != run)
                            {
                                currentAnim = run;
                                sk.AnimationState.SetAnimation(0, run, true);
                            }
                        }
                        else
                        {
                            if (currentAnim != run2)
                            {
                                currentAnim = run2;
                                sk.AnimationState.SetAnimation(0, run2, true);
                            }
                        }
                    }
                    else
                    {
                        if (FlipX)
                        {
                            if (currentAnim != run2)
                            {
                                currentAnim = run2;
                                sk.AnimationState.SetAnimation(0, run2, true);
                            }
                        }
                        else
                        {
                            if (currentAnim != run)
                            {
                                currentAnim = run;
                                sk.AnimationState.SetAnimation(0, run, true);
                            }
                        }
                    }
                }
                else
                {
                    if (currentAnim != idle)
                    {
                        currentAnim = idle;
                        sk.AnimationState.SetAnimation(0, idle, true);
                    }
                }
            }
        }

        if (GameController.instance.autoTarget.Count > 0)
        {
            SelectTarget();
        }
        else
        {
            SelectNonTarget();
        }

        movePos      = rid.velocity;
        movePos.x    = speedmove;
        movePos.y    = rid.velocity.y;
        rid.velocity = movePos;
        Jump();
        targetPos.position = Vector2.MoveTowards(targetPos.position, target, Time.deltaTime * 35f);
    }
Пример #27
0
    //Function to set animation state based on facing direction
    private void UpdateAnimation(Vector3 currentVelocity)
    {
        float horizontal = currentVelocity.x;
        float vertical   = currentVelocity.z;

        if (Mathf.Abs(horizontal) <= 0.1f && Mathf.Abs(vertical) <= 0.1f)
        {
            switch (skeletonAnimation.AnimationName)
            {
            case "runFront":
                targetAnimation = idleFront;
                break;

            case "runRight":
                targetAnimation = idleRight;
                break;

            case "runBack":
                targetAnimation = idleBack;
                break;

            default:
                targetAnimation = idleFront;
                break;
            }
        }

        else
        {
            if (Mathf.Abs(horizontal) > Mathf.Abs(vertical))
            {
                targetAnimation = runRight;
                if (horizontal < 0)
                {
                    skeletonAnimation.Skeleton.FlipX = true;
                }
                else
                {
                    skeletonAnimation.skeleton.FlipX = false;
                }
            }
            else if (Mathf.Abs(horizontal) < Mathf.Abs(vertical))
            {
                if (vertical > 0)
                {
                    targetAnimation = runBack;
                }
                if (vertical < 0)
                {
                    targetAnimation = runFront;
                }
            }
        }

        if (targetAnimation != previousAnimation)
        {
            skeletonAnimation.AnimationState.SetAnimation(0, targetAnimation, true);
        }

        previousAnimation = targetAnimation;
    }