iTween

物体移动

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 NameTypePurpose
easetypeEaseType or stringfor 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);

    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值