实现物体的移动效果
2018-01-18 14:48
190 查看
启动Unity应用程序,新建场景MoveToTarget,然后新建一个Cube立方体,再依次选择菜单栏中的GameObject--->Create--->Create Empty,接着在Inspector试图中设置其Transform组件中的position属性的x轴位-6,如下
新建c#脚本MoveToTarget.cs代码如下:using UnityEngine;
using System.Collections;
public class MoveToTarget : MonoBehaviour{
//物体移动的初始位置
private Transform start;
//物体移动的结束为止
private Transform end;
void Start(){
//获取cube
start =GameObject.Find("Cube").GetComponent<Transform>();
//获取空的GameObject
end =GameObject.Find("GameObject").GetComponent<Transform>();
}
void Update(){
transform.position = Vector3.Lerp(start.position,end.position,Time.deltaTime);
}
}将上面的MoveToTarget.cs脚本绑定到Cube游戏对象上,然后单击工具栏中的播放按钮就可以看到Cube立方体缓缓移动到GameObject对象的位置
新建c#脚本MoveToTarget.cs代码如下:using UnityEngine;
using System.Collections;
public class MoveToTarget : MonoBehaviour{
//物体移动的初始位置
private Transform start;
//物体移动的结束为止
private Transform end;
void Start(){
//获取cube
start =GameObject.Find("Cube").GetComponent<Transform>();
//获取空的GameObject
end =GameObject.Find("GameObject").GetComponent<Transform>();
}
void Update(){
transform.position = Vector3.Lerp(start.position,end.position,Time.deltaTime);
}
}将上面的MoveToTarget.cs脚本绑定到Cube游戏对象上,然后单击工具栏中的播放按钮就可以看到Cube立方体缓缓移动到GameObject对象的位置
相关文章推荐
- css3-transform-matrix 即矩阵实现物体旋转、缩放、移动效果
- Opengl 利用FBO实现物体移动轨迹变淡的效果
- Unity——Rigidbody实现真实的物体旋转效果/解决物体添加刚体后不随父物体移动/hingejoint
- 个人主页常见的头像与背景图不同步移动的下拉效果实现
- H5移动web页面触摸按钮效果实现-模拟按钮hover效果实现
- 使用jquery实现上下左右移动效果
- 属性动画实现控件类似贝塞尔曲线轨迹移动效果
- js实现的跟随鼠标移动的时钟效果(中英文日期显示)
- 实现ViewPager新手引导页的指示点跟随移动的效果
- Android 打飞机 小游戏 的实现 - 画面移动 对象封装 碰撞效果
- JS+html5实现跟随鼠标移动而散开的粒子效果
- VC实现图片移动(动画效果)
- cocos2d-js 实现双指缩放地图效果 和 单点移动效果
- mel加载一个物体不同姿态的模型实现动画效果
- 实现宠物跟随移动效果
- Android基于widget组件实现物体移动/控件拖动功能示例
- flash载入外部图片并实现淡入淡出/移动效果
- jQuery鼠标移动图片上实现放大效果
- Canvas画板实现一个简单的球在盒子内随机移动效果