如何在所需位置切换动画

发布于 2025-02-03 02:25:14 字数 1088 浏览 2 评论 0原文

我正在创建我的第一个统一游戏,以学习其工作原理。游戏:玩家需要通过跳过怪物来避免怪物。如果它与怪物相撞,则玩家死亡,石头拇指动画出现在其位置。 有一个动画师负责站立/步行动画

private Animator isWalkingAnimator; 
isWalkingAnimator = GetComponent<Animator>();  //this is in Awake

void AnimatePlayer(string animatorName) //is called from Update
    {   
        Vector2 scale = transform.localScale;
        scale.x = playerWalkingState;       
        if(playerWalkingState != 0)//walk
        {
            isWalkingAnimator.SetBool(animatorName, true);  
            prevWalkingState = playerWalkingState;
        }
        else//stand
        {
            isWalkingAnimator.SetBool(animatorName, false);
            scale.x = prevWalkingState;
        }
        transform.localScale = scale;       
    }

我的播放器脚本在private void oncollisionEnter2d(Collision2D Collision)中, if(collision.gameobject.comparetag(“敌人”))我希望iswalkingAnimator显示Thum Stone Animation

我尝试了以下操作:iswalkingAnimator.setbool(setbool)(” isdead”,false);,但什么也没发生

I'm creating my first unity game for learning how it works. the game: a player needs to avoid monsters by jumping over them. if it collides with a monster, the player dies and a stone thumb animation appear in its place.
My Player script has an Animator responsible for stand/walk animation like this

private Animator isWalkingAnimator; 
isWalkingAnimator = GetComponent<Animator>();  //this is in Awake

void AnimatePlayer(string animatorName) //is called from Update
    {   
        Vector2 scale = transform.localScale;
        scale.x = playerWalkingState;       
        if(playerWalkingState != 0)//walk
        {
            isWalkingAnimator.SetBool(animatorName, true);  
            prevWalkingState = playerWalkingState;
        }
        else//stand
        {
            isWalkingAnimator.SetBool(animatorName, false);
            scale.x = prevWalkingState;
        }
        transform.localScale = scale;       
    }

in private void OnCollisionEnter2D(Collision2D collision) If the user collides with an enemy
if (collision.gameObject.CompareTag("Enemy")) I wish isWalkingAnimator to show the thum stone animation

I've tried this: isWalkingAnimator.SetBool("isDead", false); but nothing happens

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文