Drawn line twists and becomes invisible
Hey,
so in my current 2D project I am drawing lines from game objects to connect them with another game object. The line is instantiated when clicking the first game object and then follows the mouse cursor. However, when the line is being drawn it kind of "rotates" in the 3rd dimension of the Z-axis which leads to the line getting invisible sometimes depending on the angle of the mouse cursor to the game object the line is drawn from. I don't know how to better describe this, it's like the line has a width of x and height of y but the depth is 0 and whenever it's twisted at a certain angle you cannot see it anymore because of its depth.
The code for drawing the line is the following:
void OnMouseDrag () {
line = newLineObj.GetComponent<Line>();
line.originObject = this.gameObject;
lineRenderer = newLineObj.gameObject.GetComponent<LineRenderer> ();
Vector2 screenPos = new Vector2();
Camera.main.ScreenToWorldPoint (screenPos);
lineRenderer.SetPosition (0,
new Vector3 (origin.position.x + (GetComponent<SpriteRenderer>().bounds.size.x)/2,
origin.position.y,
origin.position.z));
lineRenderer.SetPosition (1, Camera.main.ScreenToWorldPoint(Input.mousePosition));
Manager.MouseLineScript = newLineScript; // Set reference to current drawn line
Manager.MouseLineRenderer = newLineRend;
}
void OnMouseDown () {
// instantiate Line after clicking circle
newLineObj = Instantiate (Resources.Load("LinePrefab")) as GameObject;
if (newLineObj) {
newLineRend = newLineObj.GetComponent<LineRenderer> ();
newLineScript = newLineObj.GetComponent<Line> ();
}
}
Or is it something I can just set up in the Line game object prefab?
Your answer
Follow this Question
Related Questions
Can't get a smooth following line 1 Answer
Round a Line around a round thing 0 Answers
Is there a better way to fill an image[not circle or square fill]? 0 Answers
Line being drawn from point A to B 2 Answers