hello everyone
i’m new here and in javascipt iwant to make a script that can draw line when i move the mouse i’m far one step from finishing it i need your help please here is the script you can run it on your unity to see what the problem is because it’s litle bit complicated to explain it in some lines so just drag it on empty gameobject and build
var startWidth = 0.05;
var endWidth = 0.05;
var aMaterial : Material;
var n : int;
var i : int ;
var line : LineRenderer;
function Start(){
line = gameObject.AddComponent(LineRenderer);
}
function Update ()
{
line.material = aMaterial;
line.renderer.enabled = true;
line.SetWidth(startWidth, endWidth);
line.SetVertexCount(2);
var points = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.z * -1.0f));
// chaque 2sec
n=Time.time%2;
if(n==0){
line.SetPosition(0, points);
}
else if (n==1){
line.SetPosition(1, points);
}
}
please
help me finishing that
thanx 
There are two basic concepts that you will need.
The first is that you need to capture when the mouse is pressed down… and when it is released up… These are Input.GetMouseButtonDown(0) and Input.GetMouseButtonUp(0). With these, you can capture the exact point where the mouse is pressed down, and then the exact point where the mouse is up.
The next concept is depth. Since I don’t know alot about your setup or what it is you are even doing. I would suggest using a distance from the world point on a ray. (or an intersection with a plane)
Lets start off with a simple ray. The Camera.main.ScreenPointToRay(Input.mousePosition); will give you a 3d position on the near clip plane heading away from the camera. A ray of course is a start point and direction. You can then get the ray at a distance using ray.GetPoint(distance); This will give you a ray farther away from the near clip plane, thus making it where things don’t cut off abruptly.
Lastly… If you want to use planes, you will need to create a plane based on something. Lets say you are basing it on a character. Your code would be something like this:
var ray : Ray=Camera.main.ScreenPointToRay(Input.mousePosition);
var plane = new Plane(player.transform.up, player.transform.position);
var dist : float;
var hit : Vector3=Vector3.zero;
if(plane.Raycast(ray, dist)){
hit=ray.GetPoint(dist);
}
http://unity3d.com/support/documentation/ScriptReference/Plane.Plane.html
hello big mister b thanx for your reply but i’m afread that you did not understand me quite well in my previews post but never mind i figure it out thanx angain for your reply and i will post the script so everybody can use it
the script is for drawing line using linerenderer component the script should be applied to a emptygameobject
var startWidth = 0.05;
var endWidth = 0.05;
var aMaterial : Material;
var c : boolean =false;
var n : int;
var p : int=0;
var i: int =0;
var stillpresing : boolean ;
var line : LineRenderer;
var points :Vector3;
InvokeRepeating("linespawn", 0,0.05);
function Start(){
line = gameObject.AddComponent(LineRenderer);
}
function linespawn(){
if(stillpresing==true){
if( !c )
{ c=true;
i++;
}
else if( c )
{ c=false;
i++;
} }
}
function FixedUpdate ()
{
p=i+1;
line.material = aMaterial;
line.renderer.enabled = true;
line.SetWidth(startWidth, endWidth);
line.SetVertexCount(p);
if(Input.GetMouseButton (0)){
points = new Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.z * -1.0f));
stillpresing=true;
line.SetPosition(i, points );
}
else stillpresing= false;
}