Is it possible draw linerenderer in a UI space?
Hi guys, I have a small problem with LineRenderer and the UI. I'll show you a screen of my project
I wanna draw a graph that show the movement of the Cube (that you can see under the graph) that it make going up and down. And I do this in real time, with a refresh of the graph any second.
Using LineRenderer, doing it was very easy, but the drawing appear in any case in the game scene and not in the Canvas and really I don't know how can i draw the line in the black space at the right of the screen.
Can anyone help me? At the bottom you can see the code that i used to draw the actual line.
public class Graph : MonoBehaviour {
public float graphWidth;
public float graphHeight;
LineRenderer newLineRenderer;
List<int> decibels;
int vertexAmount = 50;
float xInterval;
GameObject parentCanvas;
public GameObject Diver;
List <int> profondita=new List<int>();
private float startTime;
int tempo_riferimento;
// Use this for initialization
void Start ()
{
startTime = Time.time;
newLineRenderer = GetComponentInChildren<LineRenderer>();
newLineRenderer.SetVertexCount(vertexAmount);
xInterval = 1;//graphWidth / vertexAmount;
}
void Update(){
float t = Time.time - startTime;
//ogni secondo
if (tempo_riferimento != (int)t) {
tempo_riferimento = (int)t;
profondita.Add ((int)Diver.transform.position.y+5);
Draw (profondita);
}
}
//Display 1 minute of data or as much as there is.
public void Draw(List<int> depths)
{
if (depths.Count == 0)
return;
float x = 0;
for (int i = 0; i < depths.Count; i++)
{
int _index = depths.Count - i - 1;
float y = decibels [_index];// * (graphHeight/130); //(Divide grapheight with the maximum value of decibels.
x = i * xInterval;
newLineRenderer.SetPosition(i, new Vector3(x - graphWidth / 2 , y - graphHeight / 2 , 0));
}
}
}
You could try projecting it onto the smaller display.
Give the line its own layer. Create a new camera that only shows that layer. Create a raw image and apply the material to the black screen. Create a texture and apply to the black screen material. Assign the same render texture to the new camera (render to texture).
Then whatever the camera sees should appear on the black screen.
Be sure to exclude the line layer from your main camera.
I'm doing this from memory on my mobile, so apologies if I've missed any steps, but this should hopefully give you enough to go on.