我希望我的动画能跳起来,它确实起飞了,我希望我的攻击动画能启动,但它没有。与敌人的碰撞不会导致过渡,因为整个身体找不到对撞机或触发器。我的意思是,与没有动画的简单精灵相比,我找不到哪个触发器受到动画的影响,只是使用boxcollider2D来感测场景中其他对象的触发器。
下面是我如何设置动画从一种状态转换到另一种状态。使用Animator.StringToHash(“...”)将等于GetCurrentAnimatorStateInfo(0)的AnimatorStateInfo变量与存储为整数的字符串进行比较;但它对我从来都不起作用。我的gameObject只有两种状态:空闲或防御。现在它只有一个,那就是Idle。哪个字符串进入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函数是否适用于动画,或者是否存在完全不同的方法有疑问。感谢您的回复。请放出一些光芒。
发布于 2019-07-20 05:24:44
好了,我想通了!在C-Sharp (C#)中,这一切都是通过字符串来完成的,并且整个nameHash/fullPathHash方法必须用于其他方面。我们不是使用AnimatorStateInfo访问动画状态并将该变量与nameHash进行比较,而是使用AnimatorClipInfo并识别剪辑名称。剪辑名称指定当前正在播放的动画,并且我们已准备好过渡到下一个动画。以下是工作的代码:
AnimatorClipInfo[0] m_AnimClipInfo;
string m_ClipName;
//Then a function is called to go into the defend
//animation.
void defendStart()
{
m_AnimClipInfo = this.GetComponent<Animator>.
().GetCurrentAnimatorClipInfo(0);
m_ClipName = m_AnimClipInfo[0].clip.name;
Debug.Log(m_ClipName);
//without this next IF statement, animations would lag,
//skip, or otherwise not begin immediately on call.
//Where it says, '(name of your animation)' you put the
//Debug.Log function's output.
if (m_ClipName == "(name of your animation)")
{
GetComponent<Animator>().SetBool("Defend", true);
}
}https://stackoverflow.com/questions/57105728
复制相似问题