Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 NinjaRubberBand · Jan 05, 2017 at 04:36 PM · iosiphonetap

Tapping doesn't work when played on iPhone

There spawns enemies in my game, which u have to tap to kill. The problem is, when i test my game on my iphone by exporting it through xcode, i can't tap them. When i click on them with my mouse, on my computer it works, and when i use the unity remote app, i can tap them. But not when i export it to my iPhone. Everything else works in my game, but i cant tap the enemies.

The script i use for is this:

 using UnityEngine;
  using System.Collections;
  using System.Collections.Generic;
  
  public class TouchInput : MonoBehaviour {
  
      public LayerMask touchInputMask;
      
      private List<GameObject> touchList = new List<GameObject>();
      private GameObject[] touchesOld;
      private RaycastHit hit;
      
      // Update is called once per frame
      void Update () {
          
          
  #if UNITY_EDITOR
      
      if(Input.GetMouseButton(0) || Input.GetMouseButtonDown(0)  || Input.GetMouseButtonUp(0)) {
          
          touchesOld = new GameObject[touchList.Count];
              touchList.CopyTo(touchesOld);
              touchList.Clear();
   
          
          
                    Ray ray = GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);
                  
                    
                    if(Physics.Raycast(ray,out hit,touchInputMask)) {
                        
                        GameObject recipient = hit.transform.gameObject;
                        touchList.Add(recipient);
                        
                        if(Input.GetMouseButtonDown(0)) {
                            recipient.SendMessage("OnTouchDown", hit.point, SendMessageOptions.DontRequireReceiver);
                            
                        }  if(Input.GetMouseButtonDown(0)) {
                            recipient.SendMessage("OnTouchUp", hit.point, SendMessageOptions.DontRequireReceiver);
                            
                        }  if(Input.GetMouseButtonUp(0)) {
                            recipient.SendMessage("OnTouchStay", hit.point, SendMessageOptions.DontRequireReceiver);
                            
                        }  
                  
      
                      }
                   
                   foreach (GameObject g in touchesOld) {
                       if(!touchList.Contains(g)) {
                           g.SendMessage("OnTouchExit", hit.point, SendMessageOptions.DontRequireReceiver);
                       }
                       
                   }
          
              }
      
  #endif
          
          
          
          
          
      
          }
  }



And on my enemy i have a script saying:

     void OnTouchDown () {
                 if(GameObject.Find("spawn_Controller").GetComponent<Spawn>().gameOver == false) {
 
           health = health -1;
             Instantiate(blood,gameObject.transform.position, Quaternion.identity);
              audio.PlayOneShot(gunShot, 0.7F);
                audio.PlayOneShot(bloodSplat, 0.7F);
                 }
         
     }



Can someone tell what is wrong?

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 LK84 · Jan 05, 2017 at 04:48 PM

You are using the UNITY_EDITOR directive, so of course all the code between #if UNITY_EDITOR and #endif won't be executed on your IPHONE. You basically have an empty Update() loop on your IPHONE.

Comment
Add comment · Show 2 · 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 NinjaRubberBand · Jan 05, 2017 at 04:52 PM 0
Share

Is it possible just to remove the UNITY_EDITOR and END IF and it wont affect anything?

avatar image LK84 NinjaRubberBand · Jan 05, 2017 at 05:00 PM 0
Share

You should read a little bit about preprocessor directives. They basically change the text of the source code before compilation and the result is a new source code without the code within these directives (in case if returns false). So if you use #if UNITY_EDITOR and #endifthe code between these statements is not visible except from a program ran in the Unity Editor.

You can either remove these statements or write your own implementation for IOS, using the platform directive UNITY_IOS. The same accounts for all other platforms to, of course. Have a look here: https://docs.unity3d.com/$$anonymous$$anual/PlatformDependentCompilation.html

To answer your question. Removing the directives will lead to having the same code compiled on all platforms. If this is what you want, then it is safe.

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

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

Related Questions

how to listen for "off target" taps on iOS in most efficient way? 1 Answer

Differentiating between a tap from a swipe on Android 2 Answers

Unity iOS sdk question 1 Answer

iOS Shader - Emulator vs Device Inconsistency 0 Answers

Touch.deltaTime confusion 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