【发布时间】:2018-10-29 16:43:20
【问题描述】:
我正在尝试使用 Linerenderer 在两个 UI 游戏对象之间画一条线。在场景模式下一切正常,但在游戏模式下线是不可见的。我试图改变对象的 Z 位置,但线条仍然不可见。谁能帮我?提前致谢
private LineRenderer lineRenderer;
private float counter;
private float dist;
private Vector3 aPos;
private Vector3 bPos;
public Transform origin;
public Transform destination;
public float lineDrawSpeed = 6f;
// Use this for initialization
void Start()
{
lineRenderer = GetComponent<LineRenderer>();
aPos = new Vector3(origin.position.x, origin.position.y, origin.position.z); // Using these to move the lines back
bPos = new Vector3(destination.position.x, destination.position.y, destination.position.z);
lineRenderer.SetPosition(0, aPos);
lineRenderer.SetWidth(3f, 3f);
dist = Vector3.Distance(origin.position, destination.position);
}
// Update is called once per frame
void Update()
{
if (counter < dist)
{
counter += .1f / lineDrawSpeed;
float x = Mathf.Lerp(0, dist, counter);
Vector3 pointA = aPos;
Vector3 pointB = bPos;
Vector3 pointAloneLine = x * Vector3.Normalize(pointB - pointA) + pointA;
lineRenderer.SetPosition(1, pointAloneLine);
}
}
【问题讨论】:
-
愚蠢的问题,但是你的背景是什么颜色的?我曾经做过一个 lineRenderer 相同的颜色,我认为它也是不可见的。
-
我的背景是绿色的,线条是白色的