C# 在统一中使用协同程序
我正在处理Unity,我想做的是:在10秒的时间差内播放animationType。我想让代码在动画中循环播放10秒钟。代码运行时没有错误,除了结果不是我所期望的。它播放第一个动画,拳击,持续10秒,就在它即将播放后空翻动画时,它开始对角色做一些奇怪的事情。这就是问题所在 这是我的密码:C# 在统一中使用协同程序,c#,android,arrays,unity3d,C#,Android,Arrays,Unity3d,我正在处理Unity,我想做的是:在10秒的时间差内播放animationType。我想让代码在动画中循环播放10秒钟。代码运行时没有错误,除了结果不是我所期望的。它播放第一个动画,拳击,持续10秒,就在它即将播放后空翻动画时,它开始对角色做一些奇怪的事情。这就是问题所在 这是我的密码: public class BeBot_Controller : MonoBehaviour { Animator anim; string animationType; str
public class BeBot_Controller : MonoBehaviour
{
Animator anim;
string animationType;
string[] split;
int arrayLength;
void Start()
{
//AndroidJavaClass pluginClass = new AndroidJavaClass("yenettaapp.my_bebot_plugin.My_BeBot_Plugin");
//animationType = pluginClass.CallStatic<string>("getMessage");
animationType="Null,Boxing,Backflip";
split = animationType.Split(',');
anim = gameObject.GetComponentInChildren<Animator> ();
arrayLength = split.Length;
}
// Update is called once per frame
void Update () {
if (arrayLength > 1){
StartCoroutine ("LoopThroughAnimation");
}
}
IEnumerator LoopThroughAnimation()
{
for (int i = 1 ; i < arrayLength; i++) {
animationType = split [i];
//anim.SetInteger ("AnimPar", 0);
anim.Play (animationType);
yield return new WaitForSeconds (10);
}
}
}
公共类BeBot\u控制器:单行为
{
动画师;
字符串动画类型;
字符串[]拆分;
内部排列长度;
void Start()
{
//AndroidJavaClass pluginClass=新的AndroidJavaClass(“yenettaapp.my_bebot_plugin.my_bebot_plugin”);
//animationType=pluginClass.CallStatic(“getMessage”);
animationType=“Null,装箱,倒钩”;
split=animationType.split(',');
anim=gameObject.getComponentChildren();
arrayLength=分割长度;
}
//每帧调用一次更新
无效更新(){
如果(阵列长度>1){
启动例程(“环通映像”);
}
}
IEnumerator LoopThroughAnimation()
{
对于(int i=1;i
我做错了什么?是否有其他方法可以解决此问题?由于动画循环只需调用一次,只需将
Start例程()
移动到Start()
并删除Update()
内容:
public class BeBot_Controller : MonoBehaviour
{
private Animator anim;
private string animationType;
private string[] split;
private int arrayLength;
void Start ()
{
//AndroidJavaClass pluginClass = new AndroidJavaClass("yenettaapp.my_bebot_plugin.My_BeBot_Plugin");
//animationType = pluginClass.CallStatic<string>("getMessage");
animationType = "Null,Boxing,Backflip";
split = animationType.Split(',');
anim = gameObject.GetComponentInChildren<Animator>();
arrayLength = split.Length;
// Call here
StartCoroutine(LoopThroughAnimation());
}
IEnumerator LoopThroughAnimation ()
{
for (int i = 1; i < arrayLength; i++)
{
animationType = split[i];
Debug.Log(animationType);
//anim.SetInteger ("AnimPar", 0);
anim.Play(animationType);
yield return new WaitForSeconds(10);
}
}
}
公共类BeBot\u控制器:单行为
{
私人动画师;
私有字符串animationType;
私有字符串[]拆分;
专用整数排列长度;
无效开始()
{
//AndroidJavaClass pluginClass=新的AndroidJavaClass(“yenettaapp.my_bebot_plugin.my_bebot_plugin”);
//animationType=pluginClass.CallStatic(“getMessage”);
animationType=“Null,装箱,倒钩”;
split=animationType.split(',');
anim=gameObject.getComponentChildren();
arrayLength=分割长度;
//打电话来
start例程(LoopThroughAnimation());
}
IEnumerator LoopThroughAnimation()
{
对于(int i=1;i
您需要在该类中发布完整的代码。这还不足以帮助您。协程内循环内更新函数,一定很麻烦。然而,for循环的结束括号丢失了,它工作得很好。但是我们需要什么呢???@NathanDamtewUpdate
的更新方法是针对每帧行为的。看:)是的。谢谢你@Lece