Unity3D动画回调的问题

lzx322 2015-07-09 11:06:47
我看了网上的资料(参http://bbs.csdn.net/topics/390897449帖子16楼),都是这么设置的:

using UnityEngine;
using System.Collections;

public class Try : MonoBehaviour {

void Start () {
Animation animation = gameObject.GetComponent<Animation>();
AnimationEvent evt = new AnimationEvent();
evt.time = animation.GetClip("ani").length;
evt.functionName = "Test";
animation.GetClip("ani").AddEvent(evt);

Debug.Log(act.Att.gameObject.name);
}

public void Test() {
Debug.Log("Test has been done");
}
}

为什么我这么设置后,动画运行到对应时间报这个错:
"gameObject" animationevent "Test" has no receiver!Are you missing a component?
...全文
410 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lzx322 2015-07-09
  • 打赏
  • 举报
回复
引用 1 楼 lzx322 的回复:
我是有个Manager来管理所有的动画,Test函数在Manager里,是不是Test函数必须在Animation所在gameObject上的某个脚本上?不然就会报这个错?
还真是,脚本必须在Animation所在的gameObject上,哎,我还是用携程吧,同样是FunctionName,人家NGUI就知道哪里注册哪里调用,Animation待改进。
lzx322 2015-07-09
  • 打赏
  • 举报
回复
我是有个Manager来管理所有的动画,Test函数在Manager里,是不是Test函数必须在Animation所在gameObject上的某个脚本上?不然就会报这个错?

8,305

社区成员

发帖
与我相关
我的任务
社区描述
游戏开发相关内容讨论专区
社区管理员
  • 游戏开发
  • 呆呆敲代码的小Y
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧