Line Renderer between two gameObjects

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?

Maybe try to set its width and also material.

Thanks - I’ve set the Material and width(s) in the editor. Do I need to redo this programmatically?

How about the gameobjects, can they be found? Try to make cube object field public and plug them directly in inspector

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.

Sprite shader might not work, change to simple diffuse to check it

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.

What happens if useWorldSpace is unchecked?

It doesn’t appear at all - even with no script component.

Just zero out the camera as well as cubes ,make a gap between cubes and set line width to 0.5. Test.

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