weixin_39861823
weixin_39861823
2020-12-25 20:39

How to get the completed state of an animation?

Hi there, I have character with three animation states (idle [when it’s on the ground], onAir[when it jumps], landing[when it first touch the ground]) I want to make the character play the “landing” animation just once before going back to idle Animation; the problem is I can’t find any method for that, there is one isCompleted but I don’t know how does it work. so, basically how do i play landing animation just and then keep playing idle animation.

Here is there code I use:

`//RaycastHit2D hit; float distance = 0.2f; Vector2 dir = new Vector2(0, -1);

    Debug.DrawRay (transform.position, dir * distance, Color.cyan);

    RaycastHit2D hit = Physics2D.Raycast(transform.position,dir,distance,rayMask);
    if ( hit.collider != null )
    {
        Debug.Log( "player is on the Ground!");
        if (player.animation.isPlaying && player.animation.lastAnimationName != "idle") {
            player.animation.Play ("idle", -1);
        }

    }else{

        Debug.Log( "player is in the Air!");

        if (player.animation.isPlaying && player.animation.lastAnimationName != "onAir") {
            player.animation.Play ("onAir", -1);
        }
    }

` Many thanks in advance.

该提问来源于开源项目:DragonBones/DragonBonesCSharp

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • weixin_39861823 weixin_39861823 4月前

    bump! any help?

    点赞 评论 复制链接分享
  • weixin_39874350 weixin_39874350 4月前

    Hi, You can look at the example here. https://github.com/DragonBones/DragonBonesCSharp/blob/master/Unity/Demos/Assets/Scripts/CoreElement.cs#L55

    EventObject.COMPLETE EventObject.LOOP_COMPLETE ...

    点赞 评论 复制链接分享
  • weixin_39861823 weixin_39861823 4月前

    Hi, You can look at the example here. https://github.com/DragonBones/DragonBonesCSharp/blob/master/Unity/Demos/Assets/Scripts/CoreElement.cs#L55

    EventObject.COMPLETE EventObject.LOOP_COMPLETE ...

    I will try it now, and will see if it could help me.

    点赞 评论 复制链接分享
  • weixin_39832829 weixin_39832829 4月前
    
    //Play Animation 1 times
    myArmature.animation.Play("TakeDamage", 1);
    
    //Start Coroutine or something you want.
    StartCoroutine(ToIdleFromTakeDamge);
    
    IEnumerator ToIdleFromTakeDamge()
        {
            while (myArmature.animation.GetState("TakeDamage").isPlaying)
            {
                yield return new WaitForEndOfFrame();
            }
            myArmature.animation.Play("Idle");
        }
    
    点赞 评论 复制链接分享

相关推荐