Search Unity

Unity iPhone - Does a Mouse Click = a Screen Touch?

Discussion in 'iOS and tvOS' started by xavier1764, Sep 28, 2009.

  1. xavier1764

    xavier1764

    Joined:
    Sep 17, 2009
    Posts:
    10
    Hi all,

    I've been making some controls for a game without using the GUI to see how it affects performance.

    I have an object that when touched should call the move function in the characters script. This script is in the object:

    Code (csharp):
    1.  
    2.  
    3. function OnMouseDown ()
    4. {
    5.         var MovementScript : Movement;
    6.         var charObject : GameObject = GameObject.Find("Character");
    7.         MovementScript = charObject.GetComponent(Movement);// Call Move function to Move Character Left or Right
    8.         MovementScript.MoveLeft();
    9.         Debug.Log ("Left box has been clicked");
    10. }
    11.  
    12.  
    The code compiles fine, but the debug message never happens. I was wondering if it was because I'm working with unity iPhone and there may be a different function to use a touch than there is a mouse click. Or are they the same thing and it is my code that isn't working?

    Any help would be greatly appreciated.
     
  2. Lostlogic

    Lostlogic

    Joined:
    Sep 6, 2009
    Posts:
    693
    You might want to try asking this in the iPhone section. Given that, I'd answer it if I knew the answer. I'm guess on OnMouseDown() doesn't work on the iPhone but I've seen many examples use the non-iPhone input in their code.
     
  3. xavier1764

    xavier1764

    Joined:
    Sep 17, 2009
    Posts:
    10
    Sorry, that was daft of me. I read the scripting sub-board so much I completely forgot there was a iPhone specific board.

    I wonder if I can move the thread or if an admin has to do it?
     
  4. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    A moderator has to do that and so I'll move it for you.

    As to your question, if you're using Unity iPhone have you taken care of step 1 and read the Unity iPhone Scripting Reference entry for the OnMouseDown function? It states:


    ;) :p :)
     
  5. jerrodputman

    jerrodputman

    Joined:
    Jun 4, 2008
    Posts:
    181
    Yeah, unfortunately, OnMouseDown doesn't work on the iPhone. However, Input.GetMouseButtonDown, Input.mousePosition, and associated functions DO (which is kind of odd, but welcome). If you don't have a multi-touch game, this is a good way to keep the in-editor game functioning well while still keeping touch input for the iPhone. Plus, it's good for cross-platform compatibility.
     
  6. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    Be aware than in 4.5+ they may have removed the MouseClick functionality completely from the player on mobile platforms.
    Can't speak for Apple, but on Windows Phone the code files have gone but the pointers haven't, which just means code will crash if you use Input.Mouse (whatever) in your project and deploy it.