vectorLine画线

来源:互联网 发布:淘宝大学鹰图学院 编辑:程序博客网 时间:2024/06/06 00:15
using UnityEngine;
using System.Collections;
using Vectrosity;//插件
using System.Collections.Generic;

public class DawnLine : MonoBehaviour
{
    public Material lineMaterial;
    public Transform[] pos;  目标点
    private VectorLine line;
    private int index = 0;
    void Start()
    {
        line = new VectorLine("line",new List<Vector3>(),lineMaterial,2f,LineType.Continuous); //建立vectorLine的对象
    }
    public void StartDawnLine()
    {
        iTween.ValueTo(this.gameObject, iTween.Hash("from", pos[0].position, "to", pos[1].position, "time", 2f, "onupdate", "myupdate"));
        StartCoroutine("Wait");//经过2s,不断的实时将两点之间的坐标传给myupdate
    }
    IEnumerator Wait()
//这里协程的目的是产生拐弯
    {
        index++;
        if (index<pos.Length-1){
            yield return new WaitForSeconds(2);
            iTween.ValueTo(this.gameObject, iTween.Hash("from", pos[index].position, "to", pos[index+1].position, "time", 2f, "onupdate", "myupdate"));
            StartCoroutine("Wait");
        }
    }
    public void myupdate(Vector3 value)
    {
        line.points3.Add(value);
        line.Draw3D();
    }
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            StartDawnLine();
        }
    }
}
0 0
原创粉丝点击