hi every one
I am new to unity scripting, i need to draw a line in game with mouse. i tired Line render and GL lines concept but it didn’t work.Please help me
hi every one
I am new to unity scripting, i need to draw a line in game with mouse. i tired Line render and GL lines concept but it didn’t work.Please help me
Here is a bit of code borrowed from one of my other answers:
#pragma strict
var pos1 : Vector3;
var pos2 : Vector3;
var objectHeight = 2.0; // 2.0 for a cylinder, 1.0 for a cube
function Update () {
if (Input.GetMouseButtonDown(0)) {
pos1 = Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane + 0.5);
pos1 = Camera.main.ScreenToWorldPoint(pos1);
pos2 = pos1;
}
if (Input.GetMouseButton(0)) {
pos2 = Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane + 0.5);
pos2 = Camera.main.ScreenToWorldPoint(pos2);
}
if (pos2 != pos1) {
var v3 = pos2 - pos1;
transform.position = pos1 + (v3) / 2.0;
transform.localScale.y = v3.magnitude/objectHeight;
transform.rotation = Quaternion.FromToRotation(Vector3.up, v3);
}
}