我想用Linerenderer在兩個UI GameObjects之間劃一條線。在場景模式下一切正常,但在遊戲模式下線是不可見的。我試圖改變物體的Z位置,但線條仍然不可見。誰能幫我?在此先感謝Unity3d Linerenderer不可見
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);
}
}
愚蠢的問題,但你的背景是什麼顏色?我曾經做過一個顏色相同的線條,我認爲它也是無形的。 – code11
我的背景是綠色的東西,線條是白色的 –