- Home /
Question by
Paulennonzepplien · Feb 21, 2018 at 11:17 PM ·
mouselinerendererdrawingdrawline
Gameobject is drawing a line render,when it's not supposed to !
The code here is basically about dragging a ball ,and then dropping it. When it's dropped,a line renderer will be drawn But what happens is that the line is drawn while the ball is being grabbed and moved and not when it's dropped.
if (Input.GetMouseButtonDown(0))
{
clickStart = Time.time;
Holder = true;
screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
else if (Input.GetMouseButtonUp(0) &&Time.time-clickStart>0.2) {
Debug.Log("Test1");
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
transform.position = curPosition;
Holder = false;
if (counter < dist)
{
lineRenderer.enabled = true;
Debug.Log("Test2");
counter += .1f / lineDrawSpeed;
float x = Mathf.Lerp(0, dist, counter);
Vector3 pointA = transform.position;
Vector3 temp = Enemy.position;
Vector3 pointB = new Vector3(temp.x, pointA.y, pointA.z);
Vector3 pointAlongLine = x * Vector3.Normalize(pointB - pointA) + pointB;
lineRenderer.SetPosition(0, pointA);
lineRenderer.SetPosition(1, pointAlongLine);
}
}
else
lineRenderer.enabled = false;
}
Comment