【发布时间】:2019-11-28 01:13:41
【问题描述】:
我希望我的动画会跳跃,它确实会离开地面,我希望我的攻击动画会启动,但它没有。与敌人碰撞不会导致过渡,因为整个身体都找不到对撞机或触发器。我的意思是,与没有动画并且仅使用 boxcollider2D 来感知场景中其他对象的触发器的简单精灵相比,我找不到哪个触发器受动画影响。
以下是我如何设置动画从一种状态到另一种状态的过渡。一个等于 GetCurrentAnimatorStateInfo(0) 的 AnimatorStateInfo 变量;使用 Animator.StringToHash("..."); 与存储为整数的字符串进行比较;但它从来没有对我有用。我的游戏对象只有两种状态:空闲或防御。现在它只有一个,那就是空闲。哪个字符串进入 StringToHash 函数?是动画本身的名字,还是某个参数的名字?我将向您展示代码并留下注释。请咨询...
int idleHash = Animator.StringToHash("...");
//stored as an integer and I Don't Know what to put into the
//parenthesis.
//Then a function is called to go into the Defend Animation.
void defendStart() {
AnimatorStateInfo Variable1 = GetComponent<Animator>.
().GetCurrentAnimatorStateInfo(0);
//Keep in mind the next IF statement is compared with an integer
//stored value given to us by the Animator and this is where I'm
//not sure if the string for the nameHash is related to a certain
//parameter or if it's the title of the Animation itself
if (stateInfo.nameHash == idleHash) {
GetComponent<Animator>().SetBool("Defend", true);
}
}
Defend 动画的响应速度非常慢,最好在我找到并实施正确的方法之前根本不工作。在将这些方法实现到脚本中之前,我还尝试实现与非动画精灵相同的触发概念,但这不起作用。我对 OnTriggerStay2D 或 OnTriggerExit2D 或 OnTriggerEnter2D 函数是否适用于动画或者是否有完全不同的方法有疑问。感谢您的任何回复。请提供一些启示。
【问题讨论】:
-
我的意思是在第一句话中捍卫动画而不是攻击动画。
标签: c# unity3d animation collision