LineRenderer的基本使用

Posted 大不懂

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LineRenderer的基本使用相关的知识,希望对你有一定的参考价值。

LineRenderer是unity3D中的画线工具

官方文档:https://docs.unity.cn/cn/current/ScriptReference/LineRenderer.html

基本使用

前提:新建一个Create Empty

          Inspector中点击 Add Component 找到 Line Reanderer

因为业务原因我是通过代码来控制程序的

创建一个脚本并挂载到新建的“Create Empty”中

 

 //添加LineRenderer组件  
       GameObject line_ = new GameObject();
       line_.transform.SetParent(transform);
       lineRenderer_ = line_.AddComponent<LineRenderer>();
       //设置材质  
       lineRenderer_.material = new Material(Shader.Find(Name));
       lineRenderer_.material.color = Color.red;
       //设置颜色  
       lineRenderer_.startColor = Color.red;
       lineRenderer_.endColor = Color.red;
       //设置宽度 
       lineRenderer_.startWidth = 0.2f;
       lineRenderer_.endWidth = 0.2f;
       //获取LineRenderer组件  
       //lineRenderer = GetComponent<LineRenderer>();
       lineRenderer_.positionCount = 14;

       lineRenderer_.SetPosition( 0, Camera.main.WorldToScreenPoint(new Vector3( 32672692.87354974f,8239940.766631305f, 0.0f)));
       lineRenderer_.SetPosition( 1, Camera.main.WorldToScreenPoint(new Vector3( 32672605.70108922f,8239962.183444366f, 0.0f)));
       lineRenderer_.SetPosition( 2, Camera.main.WorldToScreenPoint(new Vector3( 32672505.70622407f,8239990.383028939f, 0.0f)));
       lineRenderer_.SetPosition( 3, Camera.main.WorldToScreenPoint(new Vector3( 32672479.355226923f,8239999.256523386f, 0.0f)));
       lineRenderer_.SetPosition( 4, Camera.main.WorldToScreenPoint(new Vector3( 32672459.35794803f,8240010.304541655f, 0.0f)));
       lineRenderer_.SetPosition( 5, Camera.main.WorldToScreenPoint(new Vector3( 32672443.416976232f,8240026.654937936f, 0.0f)));
       lineRenderer_.SetPosition( 6, Camera.main.WorldToScreenPoint(new Vector3( 32672436.091900457f,8240044.585492333f, 0.0f)));
       lineRenderer_.SetPosition( 7, Camera.main.WorldToScreenPoint(new Vector3( 32672439.186205726f,8240067.1577308625f, 0.0f)));
       lineRenderer_.SetPosition( 8, Camera.main.WorldToScreenPoint(new Vector3( 32672468.940060392f,8240112.481307138f, 0.0f)));
       lineRenderer_.SetPosition( 9, Camera.main.WorldToScreenPoint(new Vector3( 32672493.266078774f,8240146.505353354f, 0.0f)));
       lineRenderer_.SetPosition( 10,Camera.main.WorldToScreenPoint( new Vector3( 32672518.78127422f,8240182.090611871f, 0.0f)));
       lineRenderer_.SetPosition( 11,Camera.main.WorldToScreenPoint( new Vector3( 32672556.505809493f,8240234.3087407835f, 0.0f)));
       lineRenderer_.SetPosition( 12,Camera.main.WorldToScreenPoint( new Vector3( 32672589.650767602f,8240280.115383893f, 0.0f)));
       lineRenderer_.SetPosition( 13, Camera.main.WorldToScreenPoint(new Vector3( 32672611.15159462f, 8240296.4439705f, 0.0f)));

1.如果想要设置颜色和宽度就必须添加材质

2.点的个数必须和输入的个数一直

3.输入的坐标要对应

 

 

源码:

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;

public class line : MonoBehaviour

    private const string Name = "Standard";
    //LineRenderer  
    private LineRenderer lineRenderer, lineRenderer_, lineRenderer_1, 
        lineRenderer1, lineRenderer1_, lineRenderer1_1,
        lineRenderer2, lineRenderer2_, lineRenderer2_1,
        lineRenderer3, lineRenderer3_, lineRenderer3_1,
        lineRenderer4_, lineRenderer4_1;
    //定义一个Vector3,用来存储鼠标点击的位置  
    private Vector3 position;
    //用来索引端点  
    private int index = 0;
    //端点数  
    private int LengthOfLineRenderer = 0;
    // Start is called before the first frame update

    private float x = 0;
    private float y = 0;
    private int  i = 0;

    private Vector3 vec;
    Vector2 p1, p2;//用来记录鼠标的位置,以便计算移动距离


    //旋转最大角度
    public int yMinLimit = -20;
    public int yMaxLimit = 80;
    //旋转速度
    public float xSpeed = 250.0f;
    public float ySpeed = 120.0f;
   

    void Start()
   
       

        lineRendererOne();
        lineRendererTwo();
        lineRendererThree();
        lineRendererFour();
        //lineRendererFive();

        //Vector3 v = Camera.main.WorldToScreenPoint(new Vector3(32999534.61492726f, 6804962.1289913505f, 0f));
        Vector3 v = Camera.main.WorldToScreenPoint(new Vector3(32672561.678379487f, 8239973.518147513f, 0f));
        print("vx:" + v.x + "  vy:" + v.y + "  vz:" + v.z);
        Camera.main.transform.position = new Vector3(v.x, v.y, -v.z);

        vec = transform.position - GameObject.Find("/Car").transform.position;

   

    // Update is called once per frame
    void Update()
   
        if (Time.frameCount % 5 == 0)
       
            if (x < 10 && y == 0)
           
                x = x + 1f;
                GameObject.Find("/Peo1").transform.position = new Vector3(x, y, 0);
           
            else
           
                if (x == 10 && y < 10)
               
                    y = y + 1;
                    GameObject.Find("/Peo1").transform.position = new Vector3(x, y, 0);
               
                else
               
                    if (y == 10 && x > 0)
                   
                        x = x - 1f;
                        GameObject.Find("/Peo1").transform.position = new Vector3(x, y, 0);
                   
                    else
                   
                        y = y - 1;
                        GameObject.Find("/Peo1").transform.position = new Vector3(x, y, 0);
                   
               
           
       

        //if (Time.frameCount % 50 == 0) 
        //
        //    i = i % 13;
        //    x = lineRenderer2_.GetPosition(i).x;
        //    y= lineRenderer2_.GetPosition(i).y;

        //    GameObject.Find("/Car").transform.position = new Vector3(x, y, 0);
        //    i++;
        //    //相机
        //    transform.position = GameObject.Find("/Car").transform.position + vec;

        //


        //if (Input.GetMouseButtonDown(0))
        //
        //    //鼠标左键按下时记录鼠标位置p1 
        //    p1 = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
        //
        //if (Input.GetMouseButton(0))
        //
        //    //鼠标左键拖动时记录鼠标位置p2   
        //    p2 = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
        //    if (transform.position.x >= 10 && transform.position.x <= 300)  //控制在20-130之内  
        //    
        //        float dx = (float)0.6 * (p2.x - p1.x);

        //        float dy = p2.y - p1.y;
        //        //鼠标左右移动  
        //        transform.Translate(-dx * Vector3.right * Time.deltaTime);
        //    
        //    else if (transform.position.x < 10 && p2.x < p1.x)
        //    
        //        float dx = (float)0.6 * (p2.x - p1.x);

        //        float dy = p2.y - p1.y;
        //        //鼠标左右移动  
        //        transform.Translate(-dx * Vector3.right * Time.deltaTime);
        //    
        //    else if (transform.position.x > 300 && p2.x > p1.x)
        //    
        //        float dx = (float)0.6 * (p2.x - p1.x);

        //        float dy = p2.y - p1.y;
        //        //鼠标左右移动  
        //        transform.Translate(-dx * Vector3.right * Time.deltaTime);
        //    
        //
        通过鼠标滚轮实现场景缩放
        鼠标滚轮的效果
        Camera.main.fieldOfView 摄像机的视野
        Camera.main.orthographicSize 摄像机的正交投影
        Zoom out
        //if (Input.GetAxis("Mouse ScrollWheel") < 0)
        //
        //    if (Camera.main.fieldOfView <= 100)
        //        Camera.main.fieldOfView += 2;
        //    if (Camera.main.orthographicSize <= 20)
        //        Camera.main.orthographicSize += 0.5F;
        //
        Zoom in
        //if (Input.GetAxis("Mouse ScrollWheel") > 0)
        //
        //    if (Camera.main.fieldOfView > 2)
        //        Camera.main.fieldOfView -= 2;
        //    if (Camera.main.orthographicSize >= 1)
        //        Camera.main.orthographicSize -= 0.5F;
        //

       


   

    //角度范围值限定
    static float ClampAngle(float angle, float min, float max)
   
        if (angle < -360)
            angle += 360;
        if (angle > 360)
            angle -= 360;
        return Mathf.Clamp(angle, min, max);
   


    private void lineRendererOne()
   
       
        添加LineRenderer组件  
        //GameObject line = new GameObject();
        //line.transform.SetParent(transform);
        //lineRenderer = line.AddComponent<LineRenderer>();
        设置材质  
        //lineRenderer.material = new Material(Shader.Find(Name));
        //lineRenderer.material.color = Color.red;
        设置颜色  
        //lineRenderer.startColor = Color.red;
        //lineRenderer.endColor = Color.red;
        设置宽度 
        //lineRenderer.startWidth = 1f;
        //lineRenderer.endWidth = 1f;
        获取LineRenderer组件  
        lineRenderer = GetComponent<LineRenderer>();
        //lineRenderer.positionCount = 14;

        //lineRenderer.SetPosition(0, new Vector3(32672692.400351748f, 8239938.879393216f, 0.0f));  //Node 2
        //lineRenderer.SetPosition(1, new Vector3(32672605.293219537f, 8239960.720262326f, 0.0f));
        //lineRenderer.SetPosition(2, new Vector3(32672505.110550538f, 8239988.646707712f, 0.0f));
        //lineRenderer.SetPosition(3, new Vector3(32672478.51397315f, 8239997.77110067f, 0.0f));
        //lineRenderer.SetPosition(4, new Vector3(32672458.25468745f, 8240009.244737328f, 0.0f));
        //lineRenderer.SetPosition(5, new Vector3(32672442.049486406f, 8240026.114417041f, 0.0f));
        //lineRenderer.SetPosition(6, new Vector3(32672434.66526077f, 8240044.796124825f, 0.0f));
        //lineRenderer.SetPosition(7, new Vector3(32672438.07336491f, 8240067.879631914f, 0.0f));
        //lineRenderer.SetPosition(8, new Vector3(32672467.621405028f, 8240113.429177782f, 0.0f));
        //lineRenderer.SetPosition(9, new Vector3(32672492.03501375f, 8240147.392816411f, 0.0f));
        //lineRenderer.SetPosition(10, new Vector3(32672517.640345156f, 8240182.911847509f, 0.0f));
        //lineRenderer.SetPosition(11, new Vector3(32672555.274279404f, 8240235.196048774f, 0.0f));
        //lineRenderer.SetPosition(12, new Vector3(32672588.68706506f, 8240281.570984258f, 0.0f));
        //lineRenderer.SetPosition(13, new Vector3(32672611.15159462f, 8240296.4439705f, 0.0f));  //Node 1 //添加LineRenderer组件  


        //添加LineRenderer组件  
       GameObject line_ = new GameObject();
       line_.transform.SetParent(transform);
       lineRenderer_ = line_.AddComponent<LineRenderer>();
       //设置材质  
       lineRenderer_.material = new Material(Shader.Find(Name));
       lineRenderer_.material.color = Color.red;
       //设置颜色  
       lineRenderer_.startColor = Color.red;
       lineRenderer_.endColor = Color.red;
       //设置宽度 
       lineRenderer_.startWidth = 0.2f;
       lineRenderer_.endWidth = 0.2f;
       //获取LineRenderer组件  
       //lineRenderer = GetComponent<LineRenderer>();
       lineRenderer_.positionCount = 14;

       lineRenderer_.SetPosition( 0, Camera.main.WorldToScreenPoint(new Vector3( 32672692.87354974f,8239940.766631305f, 0.0f)));
       lineRenderer_.SetPosition( 1, Camera.main.WorldToScreenPoint(new Vector3( 32672605.70108922f,8239962.183444366f, 0.0f)));
       lineRenderer_.SetPosition( 2, Camera.main.WorldToScreenPoint(new Vector3( 32672505.70622407f,8239990.383028939f, 0.0f)));
       lineRenderer_.SetPosition( 3, Camera.main.WorldToScreenPoint(new Vector3( 32672479.355226923f,8239999.256523386f, 0.0f)));
       lineRenderer_.SetPosition( 4, Camera.main.WorldToScreenPoint(new Vector3( 32672459.35794803f,8240010.304541655f, 0.0f)));
       lineRenderer_.SetPosition( 5, Camera.main.WorldToScreenPoint(new Vector3( 32672443.416976232f,8240026.654937936f, 0.0f)));
       lineRenderer_.SetPosition( 6, Camera.main.WorldToScreenPoint(new Vector3( 32672436.091900457f,8240044.585492333f, 0.0f)));
       lineRenderer_.SetPosition( 7, Camera.main.WorldToScreenPoint(new Vector3( 32672439.186205726f,8240067.1577308625f, 0.0f)));
       lineRenderer_.SetPosition( 8, Camera.main.WorldToScreenPoint(new Vector3( 32672468.940060392f,8240112.481307138f, 0.0f)));
       lineRenderer_.SetPosition( 9, Camera.main.WorldToScreenPoint(new Vector3( 32672493.266078774f,8240146.505353354f, 0.0f)));
       lineRenderer_.SetPosition( 10,Camera.main.WorldToScreenPoint( new Vector3( 32672518.78127422f,8240182.090611871f, 0.0f)));
       lineRenderer_.SetPosition( 11,Camera.main.WorldToScreenPoint( new Vector3( 32672556.505809493f,8240234.3087407835f, 0.0f)));
       lineRenderer_.SetPosition( 12,Camera.main.WorldToScreenPoint( new Vector3( 32672589.650767602f,8240280.115383893f, 0.0f)));
       lineRenderer_.SetPosition( 13, Camera.main.WorldToScreenPoint(new Vector3( 32672611.15159462f, 8240296.4439705f, 0.0f)));
        

        //添加LineRenderer组件  
        GameObject line_1 = new GameObject();
        line_1.transform.SetParent(transform);
        lineRenderer_1 = line_1.AddComponent<LineRenderer>();
        //设置材质  
        lineRenderer_1.material = new Material(Shader.Find(Name));
        lineRenderer_1.material.color = Color.red;
        //设置颜色  
        lineRenderer_1.startColor = Color.red;
        lineRenderer_1.endColor = Color.red;
        //设置宽度 
        lineRenderer_1.startWidth = 0.2f;
        lineRenderer_1.endWidth = 0.2f;
        //获取LineRenderer组件  
        //lineRenderer = GetComponent<LineRenderer>();
        lineRenderer_1.positionCount = 14;
        
        lineRenderer_1.SetPosition(0,  Camera.main.WorldToScreenPoint(new Vector3(32672691.92715376f,8239936.99215515f       , 0.0f)));
        lineRenderer_1.SetPosition(1,  Camera.main.WorldToScreenPoint(new Vector3(32672604.885349855f,8239959.257080287f     , 0.0f)));
        lineRenderer_1.SetPosition(2,  Camera.main.WorldToScreenPoint(new Vector3(32672504.514877006f,8239986.910386488f     , 0.0f)));
        lineRenderer_1.SetPosition(3,  Camera.main.WorldToScreenPoint(new Vector3(32672477.672719378f,8239996.285677955f     , 0.0f)));
        lineRenderer_1.SetPosition(4,  Camera.main.WorldToScreenPoint(new Vector3(32672457.15142687f,8240008.184933003f      , 0.0f)));
        lineRenderer_1.SetPosition(5,  Camera.main.WorldToScreenPoint(new Vector3(32672440.681996584f,8240025.573896145f     , 0.0f)));
        lineRenderer_1.SetPosition(6,  Camera.main.WorldToScreenPoint(new Vector3(32672433.238621075f,8240045.006757319f     , 0.0f)));
        lineRenderer_1.SetPosition(7,  Camera.main.WorldToScreenPoint(new Vector3(32672436.96052408f,8240068.601532977f      , 0.0f)));
        lineRenderer_1.SetPosition(8,  Camera.main.WorldToScreenPoint(new Vector3(32672466.302749667f,8240114.377048429f     , 0.0f)));
        lineRenderer_1.SetPosition(9,  Camera.main.WorldToScreenPoint(new Vector3(32672490.803948723f,8240148.280279469f     , 0.0f)));
        lineRenderer_1.SetPosition(10, Camera.main.WorldToScreenPoint( new Vector3(32672516.49941609f,8240183.733083151f      , 0.0f)));
        lineRenderer_1.SetPosition(11, Camera.main.WorldToScreenPoint( new Vector3(32672554.04274932f,8240236.083356764f      , 0.0f)));
        lineRenderer_1.SetPosition(12, Camera.main.WorldToScreenPoint( new Vector3(32672587.723362524f, 8240283.026584618f    , 0.0f)));
        lineRenderer_1.SetPosition(13, Camera.main.WorldToScreenPoint(new Vector3(32672611.15159462f, 8240296.4439705f        , 0.0f)));
        
   


    private void lineRendererTwo()
   
       

        //GameObject line1 = new GameObject();
        //line1.transform.SetParent(transform);
        //lineRenderer1 = line1.AddComponent<LineRenderer>();
        设置材质  
        //lineRenderer1.material = new Material(Shader.Find(Name));
        //lineRenderer1.material.color = Color.yellow;
        设置颜色  
        //lineRenderer1.startColor = Color.yellow;
        //lineRenderer1.endColor = Color.yellow;
        设置宽度  
        //lineRenderer1.startWidth = 3f;
        //lineRenderer1.endWidth = 3f;
        lineRenderer1 = GetComponent<LineRenderer>();
        //lineRenderer1.positionCount = 14;

        //lineRenderer1.SetPosition(0, new Vector3(32672692.400351748f, 8239938.879393216f, 0.0f));  //Node 2
        //lineRenderer1.SetPosition(1, new Vector3(32672567.458808575f, 8239968.417478322f, 0.0f));
        //lineRenderer1.SetPosition(2, new Vector3(32672492.792370223f, 8239989.240033938f, 0.0f));
        //lineRenderer1.SetPosition(3, new Vector3(32672469.793236095f, 8239997.939476944f, 0.0f));
        //lineRenderer1.SetPosition(4, new Vector3(32672450.926149793f, 8240010.287065925f, 0.0f));
        //lineRenderer1.SetPosition(5, new Vector3(32672435.611956365f, 8240029.85076022f, 0.0f));
        //lineRenderer1.SetPosition(6, new Vector3(32672430.132259518f, 8240049.911541708f, 0.0f));
        //lineRenderer1.SetPosition(7, new Vector3(32672435.355791673f, 8240072.201271519f, 0.0f));
        //lineRenderer1.SetPosition(8, new Vector3(32672471.697764877f, 8240122.970433356f, 0.0f));
        //lineRenderer1.SetPosition(9, new Vector3(32672481.71046298f, 8240134.53218303f, 0.0f));
        //lineRenderer1.SetPosition(10, new Vector3(32672516.593411207f, 8240187.682456717f, 0.0f));
        //lineRenderer1.SetPosition(11, new Vector3(32672549.794582553f, 8240233.792932425f, 0.0f));
        //lineRenderer1.SetPosition(12, new Vector3(32672585.20099776f, 8240282.966078931f, 0.0f));
        //lineRenderer1.SetPosition(13, new Vector3(32672611.15159462f, 8240296.4439705f, 0.0f));  //Node 1

       

        GameObject line1_ = new GameObject();
        line1_.transform.SetParent(transform);
        lineRenderer1_ = line1_.AddComponent<LineRenderer>();
        //设置材质  
        lineRenderer1_.material = new Material(Shader.Find(Name));
        lineRenderer1_.material.color = Color.yellow;
        //设置颜色  
        lineRenderer1_.startColor = Color.yellow;
        lineRenderer1_.endColor = Color.yellow;
        //设置宽度  
        lineRenderer1_.startWidth = 0.2f;
        lineRenderer1_.endWidth = 0.2f;
        //lineRenderer1 = GetComponent<LineRenderer>();
        lineRenderer1_.positionCount = 14;

        lineRenderer1_.SetPosition(0, Camera.main.WorldToScreenPoint(new Vector3(32672692.82382049f,8239940.6706006825f  , 0.0f)));
        lineRenderer1_.SetPosition(1, Camera.main.WorldToScreenPoint(new Vector3(32672567.458808575f,8239968.417478323f  , 0.0f)));
        lineRenderer1_.SetPosition(2, Camera.main.WorldToScreenPoint(new Vector3(32672493.14639256f,8239990.175979748f   , 0.0f)));
        lineRenderer1_.SetPosition(3, Camera.main.WorldToScreenPoint(new Vector3(32672470.641396977f,8239999.235464729f  , 0.0f)));
        lineRenderer1_.SetPosition(4, Camera.main.WorldToScreenPoint(new Vector3(32672452.166264135f,8240011.257810544f  , 0.0f)));
        lineRenderer1_.SetPosition(5, Camera.main.WorldToScreenPoint(new Vector3(32672437.083312195f,8240030.252667986f  , 0.0f)));
        lineRenderer1_.SetPosition(6, Camera.main.WorldToScreenPoint(new Vector3(32672431.631085046f,8240049.560296386f  , 0.0f)));
        lineRenderer1_.SetPosition(7, Camera.main.WorldToScreenPoint(new Vector3(32672436.50101789f,8240071.381486848f   , 0.0f)));
        lineRenderer1_.SetPosition(8, Camera.main.WorldToScreenPoint(new Vector3(32672472.76681633f,8240122.044614192f   , 0.0f)));
        lineRenderer1_.SetPosition(9, Camera.main.WorldToScreenPoint(new Vector3(32672482.921060726f,8240133.73765808f   , 0.0f)));
        lineRenderer1_.SetPosition(10,Camera.main.WorldToScreenPoint( new Vector3(32672517.734080847f,8240186.861134283f  , 0.0f)));
        lineRenderer1_.SetPosition(11,Camera.main.WorldToScreenPoint( new Vector3(32672551.026646283f,8240232.905802697f  , 0.0f)));
        lineRenderer1_.SetPosition(12,Camera.main.WorldToScreenPoint( new Vector3(32672586.050752487f, 8240281.329944514f, 0.0f)));
        lineRenderer1_.SetPosition(13, Camera.main.WorldToScreenPoint(new Vector3(32672611.15159462f, 8240296.4439705f, 0.0f)));
       
        GameObject line1_1 = new GameObject();
        line1_1.transform.SetParent(transform);
        lineRenderer1_1 = line1_1.AddComponent<LineRenderer>();
        //设置材质  
        lineRenderer1_1.material = new Material(Shader.Find(Name));
        lineRenderer1_1.material.color = Color.yellow;
        //设置颜色  
        lineRenderer1_1.startColor = Color.yellow;
        lineRenderer1_1.endColor = Color.yellow;
        //设置宽度  
        lineRenderer1_1.startWidth = 0.2f;
        lineRenderer1_1.endWidth = 0.2f;
        //lineRenderer1 = GetComponent<LineRenderer>();
        lineRenderer1_1.positionCount = 14;

        lineRenderer1_1.SetPosition(0, Camera.main.WorldToScreenPoint(new Vector3(32672691.976882998f,8239937.088185728f, 0.0f)));
        lineRenderer1_1.SetPosition(1, Camera.main.WorldToScreenPoint(new Vector3(32672567.458808575f,8239968.417478323f, 0.0f)));
        lineRenderer1_1.SetPosition(2, Camera.main.WorldToScreenPoint(new Vector3(32672492.43834788f,8239988.304088116f        , 0.0f)));
        lineRenderer1_1.SetPosition(3, Camera.main.WorldToScreenPoint(new Vector3(32672468.945075206f,8239996.643489145f       , 0.0f)));
        lineRenderer1_1.SetPosition(4, Camera.main.WorldToScreenPoint(new Vector3(32672449.686035458f,8240009.316321317f       , 0.0f)));
        lineRenderer1_1.SetPosition(5, Camera.main.WorldToScreenPoint(new Vector3(32672434.140600536f,8240029.4488524515f      , 0.0f)));
        lineRenderer1_1.SetPosition(6, Camera.main.WorldToScreenPoint(new Vector3(32672428.633433994f,8240050.26278703f        , 0.0f)));
        lineRenderer1_1.SetPosition(7, Camera.main.WorldToScreenPoint(new Vector3(32672434.21056545f,8240073.02105619f         , 0.0f)));
        lineRenderer1_1.SetPosition(8, Camera.main.WorldToScreenPoint(new Vector3(32672470.62871343f,8240123.89625252f         , 0.0f)));
        lineRenderer1_1.SetPosition(9, Camera.main.WorldToScreenPoint(new Vector3(32672480.499865226f,8240135.3267079815f      , 0.0f)));
        lineRenderer1_1.SetPosition(10,Camera.main.WorldToScreenPoint( new Vector3(32672515.452741567f,8240188.503779151f       , 0.0f)));
        lineRenderer1_1.SetPosition(11,Camera.main.WorldToScreenPoint( new Vector3(32672548.562518828f,8240234.680062145f       , 0.0f)));
        lineRenderer1_1.SetPosition(12,Camera.main.WorldToScreenPoint( new Vector3(32672584.351243053f, 8240284.602213323f, 0.0f)));
        lineRenderer1_1.SetPosition(13, Camera.main.WorldToScreenPoint(new Vector3(32672611.15159462f, 8240296.4439705f, 0.0f)));
        

   


    private void lineRendererThree() 
   
        //GameObject line2 = new GameObject();
        //line2.transform.SetParent(transform);
        //lineRenderer2 = line2.AddComponent<LineRenderer>();
        设置材质  
        //lineRenderer2.material = new Material(Shader.Find(Name));
        //lineRenderer2.material.color = Color.green;
        设置颜色  
        //lineRenderer2.startColor = Color.green;
        //lineRenderer2.endColor = Color.green;
        设置宽度  
        //lineRenderer2.startWidth = 3f;
        //lineRenderer2.endWidth = 3f;
        lineRenderer1 = GetComponent<LineRenderer>();
        //lineRenderer2.positionCount = 13;
        //lineRenderer2.SetPosition(0, new Vector3(32672611.15159462f, 8240296.4439705f, 0.0f));//Node 1
        //lineRenderer2.SetPosition(1, new Vector3(32672592.473847434f, 8240278.716652276f, 0.0f));
        //lineRenderer2.SetPosition(2, new Vector3(32672594.924118385f, 8240282.6694208775f, 0.0f));
        //lineRenderer2.SetPosition(3, new Vector3(32672479.61659508f, 8240123.291147739f, 0.0f));
        //lineRenderer2.SetPosition(4, new Vector3(32672447.484632872f, 8240078.4953087075f, 0.0f));
        //lineRenderer2.SetPosition(5, new Vector3(32672438.841858983f, 8240053.391307182f, 0.0f));
        //lineRenderer2.SetPosition(6, new Vector3(32672442.77343009f, 8240032.833419857f, 0.0f));
        //lineRenderer2.SetPosition(7, new Vector3(32672453.7105486f, 8240017.719668793f, 0.0f));
        //lineRenderer2.SetPosition(8, new Vector3(32672467.922120098f, 8240006.935578363f, 0.0f));
        //lineRenderer2.SetPosition(9, new Vector3(32672484.517136976f, 8239998.7332507875f, 0.0f));
        //lineRenderer2.SetPosition(10, new Vector3(32672518.854343034f, 8239987.692574954f, 0.0f));
        //lineRenderer2.SetPosition(11, new Vector3(32672562.2686892f, 8239975.609561408f, 0.0f));
        //lineRenderer2.SetPosition(12, new Vector3(32672692.400351748f, 8239938.879393216f, 0.0f));  //Node 2


        GameObject line2_ = new GameObject();
        line2_.transform.SetParent(transform);
        lineRenderer2_ = line2_.AddComponent<LineRenderer>();
        //设置材质  
        lineRenderer2_.material = new Material(Shader.Find(Name));
        lineRenderer2_.material.color = Color.green;
        //设置颜色  
        lineRenderer2_.startColor = Color.green;
        lineRenderer2_.endColor = Color.green;
        //设置宽度  
        lineRenderer2_.startWidth = 0.2f;
        lineRenderer2_.endWidth = 0.2f;
        //lineRenderer1 = GetComponent<LineRenderer>();
        lineRenderer2_.positionCount = 13;

         lineRenderer2_.SetPosition(0, Camera.main.WorldToScreenPoint(new Vector3(32672612.099416073f,8240295.445332736f , 0.0f)));
         lineRenderer2_.SetPosition(1, Camera.main.WorldToScreenPoint(new Vector3(32672593.825348154f,8240277.878874179f , 0.0f)));
         lineRenderer2_.SetPosition(2, Camera.main.WorldToScreenPoint(new Vector3(32672596.152157087f,8240281.780955356f , 0.0f)));
         lineRenderer2_.SetPosition(3, Camera.main.WorldToScreenPoint(new Vector3(32672480.851859886f,8240122.405094858f , 0.0f)));
         lineRenderer2_.SetPosition(4, Camera.main.WorldToScreenPoint(new Vector3(32672448.967217684f,8240077.984886285f , 0.0f)));
         lineRenderer2_.SetPosition(5, Camera.main.WorldToScreenPoint(new Vector3(32672440.288933333f,8240053.668051364f , 0.0f)));
         lineRenderer2_.SetPosition(6, Camera.main.WorldToScreenPoint(new Vector3(32672443.910189267f,8240033.656039588f , 0.0f)));
         lineRenderer2_.SetPosition(7, Camera.main.WorldToScreenPoint(new Vector3(32672454.60561093f,8240018.899206586f  , 0.0f)));
         lineRenderer2_.SetPosition(8, Camera.main.WorldToScreenPoint(new Vector3(32672468.47743538f,8240008.059096828f  , 0.0f)));
         lineRenderer2_.SetPosition(9, Camera.main.WorldToScreenPoint(new Vector3(32672484.517136976f,8239998.733250782f , 0.0f)));
         lineRenderer2_.SetPosition(10,Camera.main.WorldToScreenPoint( new Vector3(32672519.261027295f,8239989.15379414f  , 0.0f)));
         lineRenderer2_.SetPosition(11,Camera.main.WorldToScreenPoint( new Vector3(32672562.85899892f,8239977.700975344f  , 0.0f)));
         lineRenderer2_.SetPosition(12, Camera.main.WorldToScreenPoint(new Vector3(32672692.400351748f, 8239938.879393216f, 0.0f)));

      

        GameObject line2_1 = new GameObject();
        line2_1.transform.SetParent(transform);
        lineRenderer2_1 = line2_1.AddComponent<LineRenderer>();
        //设置材质  
        lineRenderer2_1.material = new Material(Shader.Find(Name));
        lineRenderer2_1.material.color = Color.green;
        //设置颜色  
        lineRenderer2_1.startColor = Color.green;
        lineRenderer2_1.endColor = Color.green;
        //设置宽度  
        lineRenderer2_1.startWidth = 0.2f;
        lineRenderer2_1.endWidth = 0.2f;
        //lineRenderer1 = GetComponent<LineRenderer>();
        lineRenderer2_1.positionCount = 13;
       lineRenderer2_1.SetPosition(0, Camera.main.WorldToScreenPoint(new Vector3( 32672610.20377316f,8240297.4426082745f , 0.0f)));
       lineRenderer2_1.SetPosition(1, Camera.main.WorldToScreenPoint(new Vector3( 32672591.12234672f,8240279.554430366f  , 0.0f)));
       lineRenderer2_1.SetPosition(2, Camera.main.WorldToScreenPoint(new Vector3( 32672593.696079686f,8240283.557886403f , 0.0f)));
       lineRenderer2_1.SetPosition(3, Camera.main.WorldToScreenPoint(new Vector3( 32672478.38133027f,8240124.177200615f  , 0.0f)));
       lineRenderer2_1.SetPosition(4, Camera.main.WorldToScreenPoint(new Vector3( 32672446.002048064f,8240079.00573113f  , 0.0f)));
       lineRenderer2_1.SetPosition(5, Camera.main.WorldToScreenPoint(new Vector3( 32672437.394784622f,8240053.1145629985f, 0.0f)));
       lineRenderer2_1.SetPosition(6, Camera.main.WorldToScreenPoint(new Vector3( 32672441.636670914f,8240032.010800127f , 0.0f)));
       lineRenderer2_1.SetPosition(7, Camera.main.WorldToScreenPoint(new Vector3( 32672452.815486267f,8240016.540130988f , 0.0f)));
       lineRenderer2_1.SetPosition(8, Camera.main.WorldToScreenPoint(new Vector3( 32672467.36680481f,8240005.812059887f  , 0.0f)));
       lineRenderer2_1.SetPosition(9, Camera.main.WorldToScreenPoint(new Vector3( 32672484.517136976f,8239998.733250782f , 0.0f)));
       lineRenderer2_1.SetPosition(10,Camera.main.WorldToScreenPoint( new Vector3( 32672518.447658777f,8239986.231355771f , 0.0f)));
       lineRenderer2_1.SetPosition(11,Camera.main.WorldToScreenPoint( new Vector3( 32672561.678379487f,8239973.518147513f , 0.0f)));
       lineRenderer2_1.SetPosition(12, Camera.main.WorldToScreenPoint(new Vector3(32672692.400351748f, 8239938.879393216f, 0.0f)));
        
   


    private void lineRendererFour() 
   

        //GameObject line3 = new GameObject();
        //line3.transform.SetParent(transform);
        //lineRenderer3 = line3.AddComponent<LineRenderer>();
        设置材质  
        //lineRenderer3.material = new Material(Shader.Find(Name));
        //lineRenderer3.material.color = Color.white;
        设置颜色  
        //lineRenderer3.startColor = Color.white;
        //lineRenderer3.endColor = Color.white;
        设置宽度  
        //lineRenderer3.startWidth = 3f;
        //lineRenderer3.endWidth = 3f;
        lineRenderer1 = GetComponent<LineRenderer>();
        //lineRenderer3.positionCount = 12;
        //lineRenderer3.SetPosition(0, new Vector3(32672611.15159462f, 8240296.4439705f, 0.0f));//Node 1
        //lineRenderer3.SetPosition(1, new Vector3(32672600.192200925f, 8240285.154934138f, 0.0f));
        //lineRenderer3.SetPosition(2, new Vector3(32672472.31033261f, 8240108.385940557f, 0.0f));
        //lineRenderer3.SetPosition(3, new Vector3(32672447.662834395f, 8240071.391465292f, 0.0f));
        //lineRenderer3.SetPosition(4, new Vector3(32672442.14972476f, 8240048.628678682f, 0.0f));
        //lineRenderer3.SetPosition(5, new Vector3(32672447.774210345f, 8240030.21958375f, 0.0f));
        //lineRenderer3.SetPosition(6, new Vector3(32672460.415380917f, 8240015.530779608f, 0.0f));
        //lineRenderer3.SetPosition(7, new Vector3(32672474.615814827f, 8240006.053607842f, 0.0f));
        //lineRenderer3.SetPosition(8, new Vector3(32672494.373908743f, 8239997.851279847f, 0.0f));
        //lineRenderer3.SetPosition(9, new Vector3(32672550.874929294f, 8239981.430576291f, 0.0f));
        //lineRenderer3.SetPosition(10, new Vector3(32672576.892351724f, 8239974.246513563f, 0.0f));
        //lineRenderer3.SetPosition(11, new Vector3(32672692.400351748f, 8239938.879393216f, 0.0f));  //Node 2


        GameObject line3_ = new GameObject();
        line3_.transform.SetParent(transform);
        lineRenderer3_ = line3_.AddComponent<LineRenderer>();
        //设置材质  
        lineRenderer3_.material = new Material(Shader.Find(Name));
        lineRenderer3_.material.color = Color.blue;
        //设置颜色  
        lineRenderer3_.startColor = Color.blue;
        lineRenderer3_.endColor = Color.blue;
        //设置宽度  
        lineRenderer3_.startWidth = 0.2f;
        lineRenderer3_.endWidth = 0.2f;
        //lineRenderer1 = GetComponent<LineRenderer>();
        lineRenderer3_.positionCount = 12;
        lineRenderer3_.SetPosition(0, (new Vector3(32672612.243678324f,8240295.383775912f, 0.0f)));
        lineRenderer3_.SetPosition(1, (new Vector3(32672601.420289457f,8240284.266485024f, 0.0f)));
        lineRenderer3_.SetPosition(2, (new Vector3(32672473.558890324f,8240107.554091379f, 0.0f)));
        lineRenderer3_.SetPosition(3, (new Vector3(32672449.079719827f,8240071.04829796f, 0.0f)));
        lineRenderer3_.SetPosition(4, (new Vector3(32672443.4431965f,8240049.023869929f, 0.0f)));
        lineRenderer3_.SetPosition(5, (new Vector3(32672448.849009674f,8240031.144555006f, 0.0f)));
        lineRenderer3_.SetPosition(6, (new Vector3(32672461.17019605f,8240016.661781833f, 0.0f)));
        lineRenderer3_.SetPosition(7, (new Vector3(32672475.203833155f,8240007.470049784f, 0.0f)));
        lineRenderer3_.SetPosition(8, (new Vector3(32672494.814494897f,8239999.367266491f, 0.0f)));
        lineRenderer3_.SetPosition(9, (new Vector3(32672551.275681127f,8239982.881917983f, 0.0f)));
        lineRenderer3_.SetPosition(10,( new Vector3(32672578.3839745f, 8239974.134729568f, 0.0f)));
        lineRenderer3_.SetPosition(11,( new Vector3(32672692.400351748f, 8239938.879393216f, 0.0f)));
       
        GameObject line3_1 = new GameObject();
        line3_1.transform.SetParent(transform);
        lineRenderer3_1 = line3_1.AddComponent<LineRenderer>();
        //设置材质  
        lineRenderer3_1.material = new Material(Shader.Find(Name));
        lineRenderer3_1.material.color = Color.blue;
        //设置颜色  
        lineRenderer3_1.startColor = Color.blue;
        lineRenderer3_1.endColor = Color.blue;
        //设置宽度  
        lineRenderer3_1.startWidth = 0.2f;
        lineRenderer3_1.endWidth = 0.2f;
        //lineRenderer1 = GetComponent<LineRenderer>();
        lineRenderer3_1.positionCount = 12;
        lineRenderer3_1.SetPosition(0, Camera.main.WorldToScreenPoint(new Vector3( 32672610.059510916f,8240297.504165087f, 0.0f)));
        lineRenderer3_1.SetPosition(1, Camera.main.WorldToScreenPoint(new Vector3( 32672598.9641124f,8240286.043383248f  , 0.0f)));
        lineRenderer3_1.SetPosition(2, Camera.main.WorldToScreenPoint(new Vector3( 32672471.0617749f,8240109.217789743f  , 0.0f)));
        lineRenderer3_1.SetPosition(3, Camera.main.WorldToScreenPoint(new Vector3( 32672446.24594896f,8240071.734632623f , 0.0f)));
        lineRenderer3_1.SetPosition(4, Camera.main.WorldToScreenPoint(new Vector3( 32672440.856253006f,8240048.233487432f, 0.0f)));
        lineRenderer3_1.SetPosition(5, Camera.main.WorldToScreenPoint(new Vector3( 32672446.699411016f,8240029.29461249f , 0.0f)));
        lineRenderer3_1.SetPosition(6, Camera.main.WorldToScreenPoint(new Vector3( 32672459.66056579f,8240014.399777383f , 0.0f)));
        lineRenderer3_1.SetPosition(7, Camera.main.WorldToScreenPoint(new Vector3( 32672474.0277965f,8240004.637165904f  , 0.0f)));
        lineRenderer3_1.SetPosition(8, Camera.main.WorldToScreenPoint(new Vector3( 32672493.933322594f,8239996.335293204f, 0.0f)));
        lineRenderer3_1.SetPosition(9, Camera.main.WorldToScreenPoint(new Vector3( 32672550.474177465f,8239979.979234621f, 0.0f)));
        lineRenderer3_1.SetPosition(10,Camera.main.WorldToScreenPoint( new Vector3( 32672575.400728952f,8239974.35829756f , 0.0f)));
        lineRenderer3_1.SetPosition(11, Camera.main.WorldToScreenPoint(new Vector3(32672692.400351748f, 8239938.879393216f, 0.0f)));


   

    private void lineRendererFive()
   

     
        GameObject line4_ = new GameObject();
        line4_.transform.SetParent(transform);
        lineRenderer4_ = line4_.AddComponent<LineRenderer>();
        //设置材质  
        lineRenderer4_.material = new Material(Shader.Find(Name));
        lineRenderer4_.material.color = Color.white;
        //设置颜色  
        lineRenderer4_.startColor = Color.white;
        lineRenderer4_.endColor = Color.white;
        //设置宽度  
        lineRenderer4_.startWidth = 0.2f;
        lineRenderer4_.endWidth = 0.2f;

        lineRenderer4_.enabled = true;

        //lineRenderer1 = GetComponent<LineRenderer>();
        lineRenderer4_.positionCount = 9;

        //lineRenderer4_.SetPosition(0, new Vector3(32999534.61492726f, 6804962.1289913505f, 0.0f));
        //lineRenderer4_.SetPosition(1, new Vector3(32999547.759195592f, 6804993.081014633f, 0.0f));
        //lineRenderer4_.SetPosition(2, new Vector3(32999554.524089217f, 6805010.438106284f, 0.0f));
        //lineRenderer4_.SetPosition(3, new Vector3(32999568.205178216f, 6805045.743184447f, 0.0f));
        //lineRenderer4_.SetPosition(4, new Vector3(32999583.141857374f, 6805088.855216667f, 0.0f));
        //lineRenderer4_.SetPosition(5, new Vector3(32999587.32412754f, 6805099.9096037f,    0.0f));
        //lineRenderer4_.SetPosition(6, new Vector3(32999599.93153897f, 6805141.616546586f,  0.0f));
        //lineRenderer4_.SetPosition(7, new Vector3(32999612.883062102f, 6805177.320560694f, 0.0f));
        //lineRenderer4_.SetPosition(8, new Vector3(32999639.76906279f, 6805250.64852424f,   0.0f));


        lineRenderer4_.SetPosition(0,  Camera.main.WorldToScreenPoint(new Vector3(32999534.61492726f ,6804962.1289913505f  , 0.0f)));
        lineRenderer4_.SetPosition(1,  Camera.main.WorldToScreenPoint(new Vector3(32999547.759195592f,6804993.081014633f   , 0.0f)));
        lineRenderer4_.SetPosition(2,  Camera.main.WorldToScreenPoint(new Vector3(32999554.524089217f,6805010.438106284f   , 0.0f)));
        lineRenderer4_.SetPosition(3,  Camera.main.WorldToScreenPoint(new Vector3(32999568.205178216f,6805045.743184447f   , 0.0f)));
        lineRenderer4_.SetPosition(4,  Camera.main.WorldToScreenPoint(new Vector3(32999583.141857374f,6805088.855216667f   , 0.0f)));
        lineRenderer4_.SetPosition(5,  Camera.main.WorldToScreenPoint(new Vector3(32999587.32412754f ,6805099.9096037f     , 0.0f)));
        lineRenderer4_.SetPosition(6,  Camera.main.WorldToScreenPoint(new Vector3(32999599.93153897f ,6805141.616546586f   , 0.0f)));
        lineRenderer4_.SetPosition(7,  Camera.main.WorldToScreenPoint(new Vector3(32999612.883062102f,6805177.320560694f   , 0.0f)));
        lineRenderer4_.SetPosition(8, Camera.main.WorldToScreenPoint(new Vector3(32999639.76906279f , 6805250.64852424f    , 0.0f)));

        
       
       GameObject line4_1 = new GameObject();
        line4_1.transform.SetParent(transform);
        lineRenderer4_1 = line4_1.AddComponent<LineRenderer>();
        //设置材质  
        lineRenderer4_1.material = new Material(Shader.Find(Name));
        lineRenderer4_1.material.color = Color.white;
        //设置颜色  
        lineRenderer4_1.startColor = Color.white;
        lineRenderer4_1.endColor = Color.white;
        //设置宽度  
        lineRenderer4_1.startWidth = 0.2f;
        lineRenderer4_1.endWidth = 0.2f;

        lineRenderer4_1.enabled = true;

        //lineRenderer1 = GetComponent<LineRenderer>();
        lineRenderer4_1.positionCount = 9;
        
        lineRenderer4_1.SetPosition(0, Camera.main.WorldToScreenPoint(new Vector3(32999533.684172265f,6804958.38389121f    , 0.0f)));
        lineRenderer4_1.SetPosition(1, Camera.main.WorldToScreenPoint(new Vector3(32999546.828459237f,6804989.335949674f   , 0.0f)));
        lineRenderer4_1.SetPosition(2, Camera.main.WorldToScreenPoint(new Vector3(32999553.20784327f,6805005.141811103f    , 0.0f)));
        lineRenderer4_1.SetPosition(3, Camera.main.WorldToScreenPoint(new Vector3(32999568.205178216f,6805045.743184447f   , 0.0f)));
        lineRenderer4_1.SetPosition(4, Camera.main.WorldToScreenPoint(new Vector3(32999583.141857374f,6805088.855216667f   , 0.0f)));
        lineRenderer4_1.SetPosition(5, Camera.main.WorldToScreenPoint(new Vector3(32999587.32412754f,6805099.9096037f      , 0.0f)));
        lineRenderer4_1.SetPosition(6, Camera.main.WorldToScreenPoint(new Vector3(32999598.61540275f,6805136.320458531f    , 0.0f)));
        lineRenderer4_1.SetPosition(7, Camera.main.WorldToScreenPoint(new Vector3(32999611.95243491f,6805173.575701803f    , 0.0f)));
        lineRenderer4_1.SetPosition(8, Camera.main.WorldToScreenPoint(new Vector3(32999638.838479172f, 6805246.903747603f  , 0.0f)));

       

        

   



 

 

 

 

以上是关于LineRenderer的基本使用的主要内容,如果未能解决你的问题,请参考以下文章

Unity之LineRenderer组件

LineRenderer画虚线

Unity-Linerenderer画线功能

游戏开发解答教你在Unity中使用LineRenderer制作行军蚂蚁线(行军 | 虚线 | 路径 | 线段)

游戏开发解答教你在Unity中使用LineRenderer制作行军蚂蚁线(行军 | 虚线 | 路径 | 线段)

Unity LineRenderer - 无法设置位置