This is a continuation of the following thread, but thought I should create a new one as it’s a slightly different topic: Draw on Cube/Plane/2D Surface using Setpixel? - Unity Engine - Unity Discussions
Currently, whenever the raycast hits the plane, it creates a line, but when the user hits the plane again, it just carries on using the same line renderer. But i want to create a new line renderer each time the ray cast hits the plane.
My reason for doing this is because i want to change the colours of new lines, and when i change the colour of the line at run-time, it changes the whole line to the new colour.
To visalise what’s happening, pretend that the thick part of the line indicates the colour change, so if i had a line it would look like this:
and when i change the colour, it changes the whole colour of the line to this:
_____________________________________________________
What i want though is this to happen:
__________________________****
I know i have to instantiate a new object from a prefab, but the code listed in the thread, which i will also insert below this paragraph, it would still apply to the original line renderer? I want the code to only apply to the newest line renderer game object thats being instantiated.
Texture2D tex = rend.material.mainTexture as Texture2D;
Vector2 pixelUV = hit.textureCoord;
list.Add ( new Vector3(pixelUV.x,pixelUV.y));
if (lr == null) lr = GameObject.Find("LineRenderer").GetComponent<LineRenderer>();
lr.numPositions = list.Count;
lr.SetPositions (list.ToArray());
//lr.loop = true; //the loop apparently doesn't exist in lr so it throws an error, which is why i commented it out
lr.useWorldSpace = true;
//lr.widthMultiplier = thickness;
My instinct is saying that the most efficient way is to somehow find how to target the new instantiated game object, but i don’t think thats possible, is it?