First create a rawimage, then add a linerenderer component to this image, and then build a shader.Change the shader of the shader to particles/additive, drag the shader to materials/element 0 of the Linerenderer component (you can also drag it), and finally drag the code to the empty objectThe target of the code is rawimage, the following code

using system.collections;
using system.collections.generic;
using unityengine;
public class huaxian:monobehaviour
private gameobject clone;
private linerenderer line;
int i;
//with a Linerender object
public gameobject target;
void start ()
  debug.log ("Please start writing");
//update is called once per frame
 void update ()
  if (input.getmousebuttondown (0))
    //Instantiate the object
    clone=(gameobject) instantiate (target, target.transform.position, quaternion.identity);
    //Get the Linerender component on this object
    //Set the start and end colors
    line.setcolors (color.red, color.blue);
    //Set the start and end width
    line.setwidth (0.2f, 0.1f);
   if (input.getmousebutton (0))
    //Detect every frame,The longer you hold down the mouse,The more counts
    i ++;
    //Set the number of vertices
    line.setvertexcount (i);
    //Set the vertex position (the index of the vertex,Convert the screen coordinates of the mouse click to world coordinates)
    line.setposition (i-1, camera.main.screentoworldpoint (new vector3 (input.mouseposition.x, input.mouseposition.y, 15)));
  • Previous JAVA code writing specification summary
  • Next Detailed MongoDB multi-table association query operation example