模拟itween官网上的Path-constrained Characters操作

来源:互联网 发布:淘宝ka是什么意思 编辑:程序博客网 时间:2024/06/05 08:54

iTween及iTweenPath的使用

新建一个空物体,在导入的iTweenPath插件中找到iTween Path脚本,挂到新建的空物体上:

Path Name:路径名,待会需要使用"path",iTweenPath.GetPath("前面的路径名");
Path Color:路径颜色

Path Count:路径长度
Node1为Paths路径的起点得x,y,z三个方向的值,即起点在三维场景中的位置。


C#脚本:


using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class Paths : MonoBehaviour {


    public float time;   
    bool PlayITween = true;
        
    void Start () {
        
    }


    void Update () {
        //按住空格键播放iTween动画,弹起后所有动画停止播放(这是因为ITween.pause()的括号中没有添加游戏对象,加了以后即可只控制该游戏对象上的动画播放)       
        if (Input.GetKey(KeyCode.Space))
        {
            if (PlayITween )
           {
                MoveToPath();
                PlayITween  = false;
            }
            iTween.Resume(gameObject);
        }
        else
        {
            iTween.Pause(gameObject);
        }


       

//两种方式向hashtable中添加键值对
    public void MoveToPath()
{
        Hashtable hashone = new Hashtable {
            {"path",iTweenPath.GetPath("Paths") },
            {"time", time},
            {"easetype",iTween.EaseType.linear},
            {"looptype",iTween.LoopType.loop},
            {"movetopath",true},
            {"orienttopath", true }
        };
        iTween.MoveTo(gameObject, hashone);




        //Hashtable hashOne = new Hashtable();
        //hashOne.Add("path", iTweenPath.GetPath("Paths"));
        //hashOne.Add("time", time);
        //hashOne.Add("easeType", iTween.EaseType.linear);
        //hashOne.Add("loopType", iTween.LoopType.loop);
        //hashOne.Add("movetopath", true);
        //hashOne.Add("orienttopath", true);
        //iTween.MoveTo(gameObject, hashOne);
    }
}

原创粉丝点击