- Home /
Question by
DrLlamastein · Apr 11, 2017 at 05:38 PM ·
2dlinerenderer
Line renderer not visible in game
I can't see my line in game, I am trying to draw it between two game objects but you just can't see it. https://gyazo.com/d19c03dcf9b1ced5256f3b2aae2dd67a (Also this is a 2D game)
Yes the line renderer is disabled but it gets enabled in game when I press E. When I set the positions of the line renderer this is what I do:
void Update() {
if (joint.distance > 1f) {
joint.distance -= step;
} else {
joint.enabled = false;
grapple.enabled = false;
}
if (Input.GetKeyDown(KeyCode.E)) {
targetPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
targetPos.z = 0;
hit = Physics2D.Raycast(transform.position, targetPos - transform.position, distance, groundLayer);
Debug.DrawRay(transform.position, targetPos - transform.position, Color.red);
if (hit.collider != null && hit.collider.gameObject.GetComponent<Rigidbody2D>() != null) {
joint.enabled = true;
joint.connectedBody = hit.collider.gameObject.GetComponent<Rigidbody2D>();
joint.connectedAnchor = hit.point - new Vector2(hit.collider.transform.position.x, hit.collider.transform.position.y);
joint.distance = Vector2.Distance(transform.position, hit.point);
grapple.enabled = true;
grapple.SetPosition(0, transform.position);
grapple.SetPosition(1, hit.point);
}
}
if (Input.GetKey(KeyCode.E)) {
grapple.SetPosition(0, transform.position);
}
if (Input.GetKeyUp(KeyCode.E)) {
joint.enabled = false;
grapple.enabled = false;
}
}
Any ideas?
Comment
What is the Z position of your camera? What is your camera's near value? How does you linerenderer looks in the inspector once activated (vertex positions included)? Have you managed to make a line renderer work with a possible "final state" without code? What's the difference between the one shown without code and the one you're trying to fix when it's suppose to show something (after pressing 'E')?
Your answer
![](https://koobas.hobune.stream/wayback/20220612115554im_/https://answers.unity.com/themes/thub/images/avi.jpg)