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
1
Question by Orc Master · Oct 22, 2013 at 06:42 PM · unity-android

Touch: works on Unity-Remote, doesn't work on Android device after building

In my Android game I want to use the perspective camera. When the user touches something with a specified name something happens. Using Unity-Remote on my android device everything works well, but when I build the game, the script on my android device doesn't work (probabily I think the ray isn't well cast.. but I have no idea why!) Could you kindly help? This is my script:

 private var levelStateMachine : LevelStatus;    // link to script that controls the level.
 
 var cam: Camera;
 
 function Start () {        
     levelStateMachine = FindObjectOfType(LevelStatus);
     if (!levelStateMachine)
         Debug.Log("No link to Level Status");
 }
 
 function Update () {
     if(levelStateMachine.touchEnabled){
     // Rileva il tocco
     if((Input.touchCount>0) && (Input.GetTouch(0).phase == TouchPhase.Ended)) {
         var gameObject : GameObject = GetClickedItem(Input.GetTouch(0).position);
         Debug.Log(gameObject.name);
         if(gameObject.name == "Heart") levelStateMachine.heartBeat(1);//levelStateMachine.heartBeat(1); //contatore -1;
             else if(gameObject.name == "FHeart" || gameObject.name == "SHeart") levelStateMachine.heartBeat(3); //contatore -3;
             else if(gameObject.name == "+Heart") levelStateMachine.heartBeat(2); //contatore -2
     }
     }
     
     if(Input.GetKey("up") && levelStateMachine.touchEnabled) {
         levelStateMachine.heartBeat(1);
     }
     
 }
 
 // Rileva l'elemento cliccato
 function GetClickedItem(pos: Vector2) {
     var camera : Camera = cam; //Camera.main;
     var vektor = Vector3(pos[0],pos[1],0f);
     var hit : RaycastHit;
     var ray : Ray = Camera.main.ScreenPointToRay (vektor);
     if (Physics.Raycast(ray, hit, Mathf.Infinity)) return hit.collider.gameObject;
         else return null;
 }
 
 
 //DEBUG
 
 function OnMouseDown(){
     if(levelStateMachine.touchEnabled){
         if((this.name == "Heart")) levelStateMachine.heartBeat(2);
     }
 }
Comment
Add comment · Show 2
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
avatar image meat5000 ♦ · Oct 22, 2013 at 06:54 PM 0
Share

Unfortunately, using Unity remote isn't the same as a build. It's like having the editor run on your phone.

An analogy that kinda fits,

You can play a video on a tv straight through a pc with hdmi, but this doesnt tell you if the file itself would run directly played on the tv.

avatar image Orc Master · Oct 22, 2013 at 07:10 PM 0
Share

Thanks, now I see... What can I do in order to make the script work? Do you have any suggestions about the code?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by meat5000 · Oct 22, 2013 at 07:27 PM

 if((Input.touchCount>0) && (Input.GetTouch(0).phase == TouchPhase.Ended))

Id say the above code is the problem.

Acquire the information you want in phase began. You can process it in Ended.

Also, use a different name than gameObject, as this particular name refers to the gameObject the script is attached to. On top of that, you will need to declare this object Outside of Update loop so it has scope class-wide.

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
avatar image
0

Answer by just_jim · Feb 10, 2014 at 11:28 AM

I just overcome the same problem. The problem was, that I had 2 spots in my code that I did input check. One was in the Update() where I was checking for TouchInputs and I was calling a foo() methods if I detected a touch, and also I had a onMouseDown() methode (because I was developing in a computer ofcource and I wanted to test the game with mouse clicks) that called the same foo() methode. Propably (it is very comon) in a game, a touch does a selection. You tap something to select it, and propably you hav coded already that if you select it again it deselects. So if you have both methodes (touch and mouse) because unity on a mobile translates touches to mouse events, you'll call foo() twice. So your object will be selected and deselected on an instance and you would think that touch didn't work. But it did. So check if you have a leftOver OnMouseDown methode somewhere and comment it out before you build. I hope taht helped...

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

16 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 avatar image avatar image

Related Questions

Export & Install APK on Android 5 Answers

Sensitivity on Android Input.acceleration 2 Answers

Why do my GUI elements move when exported to Android? 1 Answer

Bugsense in unity(android) 1 Answer

Android uses Bluetooth keyboard as input 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