地形画线

using UnityEngine;
using System.Collections;
 
public class GLTest : MonoBehaviour
{


    public Vector3 target;
    public float height;
    public LineRenderer linerenderer;
    public float distance;


    private void Start()
    {
        height = Terrain.activeTerrain.SampleHeight(target);
        distance = (target - transform.position).magnitude;
        int dis = (int)distance;
        linerenderer.positionCount = dis;
        for (int i = 0; i < dis; i++)
        {
            transform.position = Vector3.MoveTowards(transform.position, target, 1);


            linerenderer.SetPosition(i, new Vector3(transform.position.x, Terrain.activeTerrain.SampleHeight(transform.position), transform.position.z));
        }
        //linerenderer.SetPosition(0, transform.position);
        //linerenderer.SetPosition(1, target);


    }


    private void Update()
    {
        
    }


}



    public Vector3[] target;
    //public float height;
    public LineRenderer linerenderer;
    //public float distance;
    public int lineCount;
    private void Start()
    {
        for (int i = 1; i < target.Length; i++)
        {
            float height = Terrain.activeTerrain.SampleHeight(target[i]);
            float distance = (target[i] - transform.position).magnitude;
            int dis = (int)distance;
            lineCount += dis;
            linerenderer.positionCount = lineCount;
            for (int j = lineCount-dis; j < lineCount; j++)
            {
                transform.position = Vector3.MoveTowards(transform.position, target[i], 1);
   linerenderer.SetPosition(j, new Vector3(transform.position.x, Terrain.activeTerrain.SampleHeight(transform.position), transform.position.z));
            }
        }


    }


阅读更多
换一批

没有更多推荐了,返回首页