- Home /
Question by
mali0 · Jul 28, 2021 at 07:30 PM ·
androidlinerenderer
Help With LineRenderer on android
So i am trying to use linerenderer on my mobile game but what works in pc wont work in mobile. Basically List populates in pc but doest populates in Android ,so when list is emphty there is no line in android this is pc code :
private LineRenderer lineRenderer;
private List<Vector3> points = new List<Vector3>();
public Action<IEnumerable<Vector3>> onPathCreated = delegate { };
private void HandleMouse()
{
if (Input.GetButtonDown("Fire1"))
points.Clear();
if (Input.GetButton("Fire1"))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo))
{
if (DistanceToLastPoint(hitInfo.point) > 1f)
{
points.Add(hitInfo.point);
lineRenderer.positionCount = points.Count;
lineRenderer.SetPositions(points.ToArray());
lineRenderer.alignment = LineAlignment.View;
}
}
}
else if (Input.GetButtonUp("Fire1"))
onPathCreated(points);
}
this is android
private void HandleTouch()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Moved)
{
points.Clear();
}
if (Input.touchCount == 2)
{
touch = Input.GetTouch(1);
if (touch.phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay(touch.position);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo))
{
if (DistanceToLastPoint(hitInfo.point) > 1f)
{
points.Add(hitInfo.point);
lineRenderer.positionCount = points.Count;
lineRenderer.SetPositions(points.ToArray());
lineRenderer.alignment = LineAlignment.View;
}
}
}
if (touch.phase == TouchPhase.Ended)
{
onPathCreated(points);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Touch doesn't work in the DrawLine project... 1 Answer
LineRenderer working half of the time 2 Answers
Linerender width doesnt work on android 0 Answers
Line renderer not smooth 0 Answers
Smooth draw curve line 0 Answers