I'm using this code here (very simple). It draws a line:
Create a new scene, Create a cylinder, Scale the cylinder to (0.005, 1.0, 0.005), Put the following script on the cylinder
#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);
}
}
When I move the mouse fast, the line lags. It also lags on the smartphone. I put that code in OnGUI, because I read somewhere, that it is faster than Update. It's still lagging.
I write a game. Is there a way to speed up the Line drawing. I mean like hardware accelerated = true? Or I'm on the wrong way?
I know, that there are some 2d linedrawing codes and linerenderer. But I want to make it like above. I want to stretch an object.