博客
关于我
Unity中执行完动画,子物体的移动问题
阅读量:346 次
发布时间:2019-03-04

本文共 583 字,大约阅读时间需要 1 分钟。

简述问题

在Unity工程中,对父物体添加Animation,程序运行后,对子物体的移动问题。

拆分父物体

程序运行开始,执行为父物体添加的Animation动画,执行完后,父物体被拆分为几个子物体。

问题

虽然执行了Animation动画,但父物体和子物体的层级关系还是存在。而且将一个移动代码赋给其中一个子物体,类似于:

transform.position = Vector3(1,1,1);
将子物体移动到(1,1,1);但执行的时候发现,子物体移动到指定位置后,一闪又回到了初始位置。

解决办法

问题根源

因为父物体的Animation动画执行完后,并没有对其进行判断。

在这里插入图片描述
实验之后发现,如果我将Animator取消勾选,然后运行,发现可以对子物体进行移动,所以我判断应该是Animator的问题。Animator可用于判断动画是否执行完。

解决

我用最简单的方法处理了这个问题。在我要移动子物体的时候,对父物体的Animator销毁,然后就可以移动子物体了。

Destroy(GameObject.Find(“cycle”).GetComponent());
然后使用
transform.position = Vector3(1,1,1);就可以移动物体。
当然如果能对动画状态进行判断,然后处理应该会更好。
这里推荐一下别人写的Animator的用法:

转载地址:http://fuve.baihongyu.com/

你可能感兴趣的文章
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>