[英]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.