C# 用于在Unity中的某些动画期间平滑过渡和碰撞的动画

C# 用于在Unity中的某些动画期间平滑过渡和碰撞的动画,c#,unity3d,animation,collision,C#,Unity3d,Animation,Collision,我希望我的动画能够跳跃,它确实能够从地面上起飞,我希望我的攻击动画能够启动,但它没有。与敌人的碰撞不会导致任何转换,因为整个身体都找不到碰撞器或触发器。我的意思是,与简单的精灵相比,我找不到哪个触发器受动画的影响,这些精灵不设置动画,只使用boxcollider2D来感知场景中其他对象的触发器 下面是我如何设置动画从一种状态到另一种状态的转换。等于GetCurrentAnimatorStateInfo(0)的AnimatorStateInfo变量;与使用Animator.StringToHash

我希望我的动画能够跳跃,它确实能够从地面上起飞,我希望我的攻击动画能够启动,但它没有。与敌人的碰撞不会导致任何转换,因为整个身体都找不到碰撞器或触发器。我的意思是,与简单的精灵相比,我找不到哪个触发器受动画的影响,这些精灵不设置动画,只使用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);
                                            }
                       }
int idleHash=Animator.StringToHash(“…”);
//存储为整数,我不知道要将什么放入
//括号。
//然后调用一个函数进入防御动画。
void start(){
AnimatorStateInfo Variable1=GetComponent。
().GetCurrentAnimatorStateInfo(0);
//请记住,下一个IF语句将与整数进行比较
//由动画师提供给我们的存储值,这就是我的位置
//不确定nameHash的字符串是否与某个
//参数,或者如果它是动画本身的标题
if(stateInfo.nameHash==idleHash){
GetComponent().SetBool(“防御”,true);
}
}

防御动画的响应非常慢,最好在我找到并实现正确的方法之前根本不工作。在将这些方法实现到脚本中之前,我还尝试实现与未设置动画的精灵相同的触发器概念,但这不起作用。我对OnTiggerStay2D、OnTiggerExit2D或OnTiggerInter2D函数是否与动画一起工作,或者是否有完全不同的方法存在疑问。谢谢你的回复。请说清楚。

好吧,我想出来了!在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);
    }
}
AnimatorClipInfo[0]m_animiclipinfo;
字符串m_ClipName;
//然后调用一个函数以进入防御
//动画。
void start()
{
m_AnimClipInfo=this.GetComponent。
()GetCurrentAnimatorClipInfo(0);
m_ClipName=m_AnimClipInfo[0].clip.name;
Log(m_ClipName);
//如果没有这个next IF语句,动画就会滞后,
//跳过,或不立即开始呼叫。
//上面写着,“(你的动画名称)”你把
//Debug.Log函数的输出。
如果(m_ClipName==“(动画名称)”)
{
GetComponent().SetBool(“防御”,true);
}
}

好吧,我想出来了!在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);
    }
}
AnimatorClipInfo[0]m_animiclipinfo;
字符串m_ClipName;
//然后调用一个函数以进入防御
//动画。
void start()
{
m_AnimClipInfo=this.GetComponent。
()GetCurrentAnimatorClipInfo(0);
m_ClipName=m_AnimClipInfo[0].clip.name;
Log(m_ClipName);
//如果没有这个next IF语句,动画就会滞后,
//跳过,或不立即开始呼叫。
//上面写着,“(你的动画名称)”你把
//Debug.Log函数的输出。
如果(m_ClipName==“(动画名称)”)
{
GetComponent().SetBool(“防御”,true);
}
}

我在第一句中的意思是防御动画而不是攻击动画。我在第一句中的意思是防御动画而不是攻击动画。