Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by thinkfuture · May 31, 2013 at 02:08 AM · androidcrashswipe

Swipe Script Crashes on Android, Not iOS

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by saschandroid · May 31, 2013 at 08:35 AM

Try using

 Touch touch = Input.GetTouch(0);

or replace all touch with Input.GetTouch(0).

I always use this and had no problems with inputs on Android so far.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

galaxy s5 crash unity 4.5.1f3 0 Answers

Crash app unity 4.5.5f1 on nexus 7 (Android 4.4.4) 0 Answers

Unity 5 GUI crashes android 2 Answers

android app crashes after unity screen (maybe because of AdMob?) 0 Answers

Random crashes in Android build 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges