- Home /
Question by
MeneerMalik · Dec 02, 2014 at 03:36 PM ·
buildtouchremote
Touch recognized in editor, not in build
As the title suggests, i have a game which runs fine in unity remote, but once built the touch input stops working. Below is the script i'm using:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class TouchLine : MonoBehaviour
{
private LineRenderer line;
private List<Vector3> lineList;
private List<Vector2> colliderList;
private new EdgeCollider2D collider;
// Structure for line points
struct myLine
{
public Vector3 StartPoint;
public Vector3 EndPoint;
};
void Awake()
{
// Create line renderer component and set its property
line = gameObject.AddComponent<LineRenderer>();
line.material = new Material(Shader.Find("Sprites/Diffuse"));
line.SetVertexCount(0);
line.SetWidth(0.1f,0.1f);
line.useWorldSpace = true;
lineList = new List<Vector3>();
// Create edgecollider2D and set its property
collider = gameObject.AddComponent<EdgeCollider2D>();
colliderList = new List<Vector2>();
}
// -----------------------------------
void Update ()
{
for (int i = 0; i < Input.touchCount; i++)
{
Touch touch = Input.GetTouch(i);
if (touch.phase == TouchPhase.Began)
{
Vector3 position = Camera.main.ScreenToWorldPoint(touch.position);
position.z = 1;
lineList.RemoveRange (0, lineList.Count);
colliderList.RemoveRange (0, colliderList.Count);
colliderList.Add (position);
lineList.Add (position);
line.SetVertexCount (lineList.Count);
line.SetPosition (lineList.Count - 1, (Vector3)lineList [lineList.Count - 1]);
}
else if (touch.phase == TouchPhase.Ended)
{
Vector3 position = Camera.main.ScreenToWorldPoint(touch.position);
position.z = 1;
lineList.Add (position);
line.SetVertexCount (lineList.Count);
line.SetPosition (lineList.Count - 1, (Vector3)lineList [lineList.Count - 1]);
colliderList.Add (position);
setPoints();
}
}
}
void setPoints()
{
collider.points = colliderList.ToArray();
}
}
I hope someone can help me out!
edit:
I'm building it for Android, and the phone is a Samsung Galaxy S4 Mini!
Comment
good call, i forgot to mention that it was on Android and on a Galaxy S4 $$anonymous$$ini. Edited it in, thanks!
Experiencing similar issues with windows 7 mul$$anonymous$$ch screen. Editor playmode takes touch input but standalone build does not. Still looking for answers. I'll pop back here if I figure anything out.