stirl
February 2, 2016, 9:09pm
1
Hi,
Ok, I’m new and I have searched through similar answers and I have finally accepted I need help.
I’m trying to connect two objects with a line. This is the code, the gameObject with the Line Renderer component is showing the right 0 and 1 positions but I am not seeing it on the scene when it runs.
using UnityEngine;
using System.Collections;
public class onload : MonoBehaviour {
private GameObject cubeBottom;
private GameObject cubeTop;
void Start ()
{
cubeBottom = GameObject.Find("go1");
cubeTop = GameObject.Find("go2");
LineRenderer lineRenderer = GetComponent<LineRenderer> ();
lineRenderer.SetPosition (0, cubeBottom.transform.localPosition);
lineRenderer.SetPosition (1, cubeTop.transform.localPosition);
}
void Update ()
{
}
}
I have tried both position and localPosition as you can see. localPosition returns the right coords of the go1 and go2 gameObjects.
Can anyone spot anything obviously wrong?
domkia
February 2, 2016, 9:22pm
2
Maybe try to set its width and also material.
stirl
February 2, 2016, 9:28pm
3
Thanks - I’ve set the Material and width(s) in the editor. Do I need to redo this programmatically?
domkia
February 2, 2016, 9:33pm
4
How about the gameobjects, can they be found? Try to make cube object field public and plug them directly in inspector
stirl
February 2, 2016, 9:35pm
5
Yeah, it’s finding the objects - when I click on the object that has the line renderer on at run time it’s coordinates are being set to the positions of the two object. But there’s no line.
domkia
February 2, 2016, 9:37pm
6
Sprite shader might not work, change to simple diffuse to check it
stirl
February 2, 2016, 9:47pm
7
I don’t think it’s that - if I deselect the script from the line renderer object and run, this is what I get.
Which is really weird.
domkia
February 2, 2016, 10:00pm
8
What happens if useWorldSpace is unchecked?
stirl
February 2, 2016, 10:05pm
9
It doesn’t appear at all - even with no script component.
domkia
February 2, 2016, 10:16pm
10
Just zero out the camera as well as cubes ,make a gap between cubes and set line width to 0.5. Test.
stirl
February 2, 2016, 10:24pm
11
I’m a total newb.
The camera wasn’t covering the part of the canvas where it was all happening…
you getting me to look at the camera brought me to my senses, many thanks wonker21.
1 Like