两个对象的轴心首先要在建模软件中设定好,Line Renderer的位置应用的是模型对象轴心位置
代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class lineScript1 : MonoBehaviour
{
public LineRenderer line;//组件所依赖的对象
public Transform pos1;//位置A
public Transform pos2;//位置B(可以一直添加新的位置)
// Start is called before the first frame update
void Start()
{
line.positionCount = 2;//两个位置,可以再增加更多的位置,但是会形成连续的线
}
// Update is called once per frame
void Update()
{
line.SetPosition(0, pos1.position);//位置A
line.SetPosition(1, pos2.position);//位置B(可以一直添加新的位置)
}
}
第一栏 放置挂载line renderer组件的对象
pos1 放置 连接线的对象A
pos2 放置 连接线的对象B