I’m porting my game to Android and for some reason this script which works fine on iOS crashes when I run it on Android. I’ve combed over it and docs online to no avail and thought I’d post it here to see if anyone out there has seen something similar:
using UnityEngine;
using System.Collections;
public class ArenaSwipe : MonoBehaviour {
public float comfortZone = 70.0f;
public float minSwipeDist = 14.0f;
public float maxSwipeTime = 0.5f;
public float swipeTime;
public float swipeValueX;
public float swipeValueY;
public float swipeDistX;
public float swipeDistY;
private Vector2 startPos;
private GameObject player;
static public float lastSwipeTime;
void Start(){
player = GameObject.Find("fighter");
}
void Update () {
if (Input.touchCount > 0)
{
Touch touch = Input.touches[0];
switch (touch.phase)
{
case TouchPhase.Began:
startPos = touch.position;
break;
case TouchPhase.Ended:
swipeDistY = (new Vector3(0, touch.position.y, 0) - new Vector3(0, startPos.y, 0)).magnitude;
swipeDistX = (new Vector3(0, touch.position.x, 0) - new Vector3(0, startPos.x, 0)).magnitude;
if (swipeDistX > minSwipeDist | swipeDistY > minSwipeDist){
if (swipeDistY > swipeDistX)
{
swipeValueY = Mathf.Sign(touch.position.y - startPos.y);
if (swipeValueY > 0)
{
MovePlayer.move = "up";
player.SendMessage("Move");
} else {
MovePlayer.move = "down";
player.SendMessage("Move");
}
} else {
swipeValueX = Mathf.Sign(touch.position.x - startPos.x);
if (swipeValueX > 0)
{
MovePlayer.move = "right";
player.SendMessage("Move");
}
else
{
MovePlayer.move = "left";
player.SendMessage("Move");
}
}
Debug.Log ("X:"+swipeDistX+" Y:"+swipeDistY);
}
break;
}
}
}
}
The level loads fine, the moment you touch the screen it craps out. I can disable just this script on the page and all other touch functions work fine - I run adb logcat and it reveals nothing - just that the app crashed, as you can see below…app is called com.hellofuture.app
D/SensorService( 735): SensorDevice::activating sensor handle=0 ns=200000000
I/SurfaceFlinger( 217): id=3804 Removed TurfaceView (-2/7)
I/ActivityManager( 735): Process **com.hellofuture.app** (pid 23819) (adj 0) has died.
E/Sensors ( 735): Mag old sensor_state 133, new sensor_state : 129 en : 0
D/SensorService( 735): SensorDevice::activating sensor handle=1 ns=20000000
W/ContextImpl( 735): Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1323 com.android.server.am.ActivityManagerService.cleanUpApplicationRecordLocked:12344 com.android.server.am.ActivityManagerService.handleAppDiedLocked:3566 com.android.server.am.ActivityManagerService.appDiedLocked:3670 com.android.server.am.ActivityManagerService$AppDeathRecipient.binderDied:981
W/ActivityManager( 735): Force removing ActivityRecord{43791648 u0 com.hellofuture.app/com.unity3d.player.UnityPlayerNativeActivity}: app died, no saved state
If anyone can give me any ideas, I’d appreciate them greatly! Don’t understand why this works just fine on iOS but not Android…
Thanks…Chris