简体   繁体   English

使用 1 次后如何取消动画?

[英]How do i cancel an animation after is has been used 1 time?

As the title says I want to cancel an animation after I attacked once and the monster lost 10 lives , and run it again if I attack again and the monster loses another 10 lives .正如标题所说,我想在我攻击一次并且怪物失去10条生命后取消动画,如果我再次攻击并且怪物又失去10条生命,则再次运行它。 I have tried to find the answer already but I couldn't find anything that works .我已经试图找到答案,但我找不到任何有效的方法。 So far I managed to get it to work the first time I shoot , after he loses 10 lives and the animation goes to idle instead of the animation defend.到目前为止,我在第一次射击时设法让它工作,在他失去 10 条生命并且动画进入空闲状态而不是动画防御之后。 But the second time nothing happens , he just stays in idle .但第二次什么也没发生,他只是闲着。 The code should work unless I am missing something?(I still have to add some code (if it was working)).除非我遗漏了什么,否则代码应该可以工作?(我仍然需要添加一些代码(如果它可以工作))。

```
public GameObject monster;
private Animator anim;
public GameObject player;
private Transform player_pos;
private Target target;
private float i = 0;
private float y = 0;
// Start is called before the first frame update
void Start()
{
    anim = monster.GetComponent<Animator>();
    player_pos = player.GetComponent<Transform>();
    target = monster.GetComponent<Target>();
}

// Update is called once per frame
void Update()
{
    if(target.health <= 0)
    {
        anim.SetBool("isDead", true);
    }
    if (target.health < 100 && i<1)

    {
        anim.SetBool("isDamaged", true);
        i++;
    }
    else
    {
        anim.SetBool("isDamaged", false);
        anim.SetBool("isIdle", true);
    }
    if (target.health == 90 && y < 1)

    {
        y++;
        anim.SetBool("isDamaged", true);
    }
    else
    {
        anim.SetBool("isDamaged", false);
        anim.SetBool("isIdle", true);
    }

}

对于遇到此问题的任何人,我发现了如何,只需将参数类型从 bool 替换为 trigger。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 处置后如何创建对象? - How do I create an object after it has been disposed? 加载后如何更新DataGrid? - How do I update a DataGrid after it has already been loaded? Excel VSTO如何检查在激发WorkbookBeforeClose事件后是否从对话框中触发了取消按钮? - Excel VSTO how to check if the Cancel button has been triggered from the dialog after the WorkbookBeforeClose event is fired? 一旦使用StreamWriter,我将如何重新启动它? - How would i restart StreamWriter onced it has been used? 如何检测第一次运行 ClickOnce 部署的应用程序? - How do I detect the first time a ClickOnce-deployed application has been run? 为什么在调用取消后线程继续运行? - Why threads continue to run after a cancel has been called? 我的 function 读取 blob 后如何删除它 - How do I delete a blob after it has been read by my function 在Xamarian iOS应用程序中单击按钮后X秒钟,如何触发事件? - How do I trigger an event X seconds after a button has been clicked in a Xamarian iOS application? 从 Outlook 发件箱文件夹发出后如何修改电子邮件? - How do I modify an email after it has been sent out from Outlook Outbox folder? innerXML删除后,如何删除C#中的空标签? - How do I remove empty tags in C# after innerXML has been removed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM