物体移动
MoveTo BACK TO TOP
Changes a GameObject’s position over time to a supplied destination.
经过一段时间改变物体的位置到提供的目标
MoveTo(GameObject target, Vector3 position, float time)
MoveTo(GameObject target, Hashtable args)
其中重要参数
Property Name | Type | Purpose |
---|---|---|
easetype | EaseType or string | for the shape of the easing curve applied to the animation |
参数可视化理解
http://www.robertpenner.com/easing/easing_demo.html
参考实例
http://www.ceeger.com/forum/read.php?tid=62&page=1
个人觉得在awake 设定参数比较合适
using UnityEngine;
using System.Collections;
public class MyEnemyControl : MonoBehaviour {
//路径寻路中的所有点
private Hashtable args = new Hashtable();
public Transform paths;
private Vector3 [] points;
void Awake(){
points = new Vector3[paths.childCount];
for (int i = 0; i < paths.childCount; i++) {
points[i]= paths.GetChild(i).position;
}
args = new Hashtable();
//设置路径的点
args.Add("path",points);
//设置类型为线性,线性效果会好一些。
args.Add("easeType", iTween.EaseType.linear);
//设置寻路的速度
args.Add("speed",20f);
//是否先从原始位置走到路径中第一个点的位置
args.Add("movetopath",true);
//是否让模型始终面朝当面目标的方向,拐弯的地方会自动旋转模型
//如果你发现你的模型在寻路的时候始终都是一个方向那么一定要打开这个
args.Add("orienttopath",true);
//循环模式
args.Add ("looptype", iTween.LoopType.none);
}
void Start ()
{
//让模型开始寻路
iTween.MoveTo(this.gameObject,args);
}
void OnDrawGizmos()
{
//在scene视图中绘制出路径与线
iTween.DrawLine(points,Color.yellow);
iTween.DrawPath(points,Color.red);
}
}