- Home /
Touch won't work outside of remote
I've made sure to keep all touch handling within update to avoid input conflicts and when i tested in Unity everything worked correctly. I don't require multiple outputs but when i started only looking for touch '0' didn't work (though that was just testing with builds so it's likely the same issue). Here is my Touch handler for the types of taps I want to distinguish from.
public class TouchHandler extends MonoBehaviour{ private static var tapTime : float;
enum TouchType{NoTap = 0, Tap = 1, DoubleTap = 2, Hold = 3};
public static var curTouch : TouchType;
function Update(){
if(Input.touchCount >= 1){
for(var touch : Touch in Input.touches){
switch (touch.phase){
case TouchPhase.Began:
if(Time.time > tapTime){
tapTime = Time.time + 0.5;
curTouch = TouchType.Tap;
}else{
curTouch = TouchType.DoubleTap;
//print("DoubleTap!");
}
break;
case TouchPhase.Stationary:
if(Time.time > tapTime){
curTouch = TouchType.Hold;
}
break;
}
}
}else if(curTouch != TouchType.NoTap){
curTouch = TouchType.NoTap;
}
}
}
And here's the simple player movement script for moving around based upon the touches (It's for testing a cardboard vr game idea).
public class PlayerMovement extends MonoBehaviour{
public var speed : float = 2;
public var moving : boolean;
private var curForward : Vector3;
private var cam : GameObject;
private var rig : Rigidbody;
private var tapTime : float;
private var gettingTapType : boolean;
/*enum tapType{noTap, oneTap, doubleTap};
private var curTap : tapType = tapType.noTap;*/
function Start(){
cam = GameObject.Find("Main Camera");
rig = GetComponent(Rigidbody);
}
function Update(){
if(TouchHandler.curTouch == TouchHandler.TouchType.Hold){
MoveForward();
}
var newForward : Vector3 = cam.transform.forward;
curForward = new Vector3(newForward.x, 0, newForward.z);
}
/*function LateUpdate(){
var newForward : Vector3 = cam.transform.forward;
curForward = new Vector3(newForward.x, 0, newForward.z);
//if(moving){ MoveForward();}
}*/
function MoveForward(){
rig.velocity = curForward * speed;
}
}
It's all in js but I wouldn't mind a .cs solution if the logic ends up the same. Even if it isn't that just means I'll have to use cs which is a pain, but not impossible for me to do. Maybe I'll figure out what happens, but if you do instead, thank you~!
Answer by ThatOwlGuy · Jan 03, 2017 at 07:41 AM
Turns out what was wrong is that the touches in this way is something recognized by iOS devices only. Not sure anyone else would look for this solution, but just in case...
Your answer
![](https://koobas.hobune.stream/wayback/20220612060020im_/https://answers.unity.com/themes/thub/images/avi.jpg)