Search Unity

Functions OnMouseOver , OnMouseExit and OnMouseDown on Android ?

Discussion in 'Android' started by KeepTrying, Feb 24, 2011.

  1. KeepTrying

    KeepTrying

    Joined:
    Feb 23, 2011
    Posts:
    119
    Hi folks
    Why these functions don`t work on Android or other touch devices ?
    I trying around a week to make it happens but no luck whats wrong with my code ?
    See that sample code

    startnewgame.js

    function Start(){
    guiText.material.color=Color.yellow;
    }
    function OnMouseOver () {
    guiText.material.color=Color.green;
    }

    function OnMouseExit(){
    guiText.material.color=Color.yellow;
    }

    function OnMouseDown(){
    PlayerPrefs.SetInt("falllevel", 0);
    Application.LoadLevel(Application.loadedLevel);
     
  2. defjr

    defjr

    Joined:
    Apr 27, 2009
    Posts:
    436
    AFAIK OnMouse* functions don't work on mobile. I typically use the touch class and raycasts to trigger touch events. :)
     
  3. KeepTrying

    KeepTrying

    Joined:
    Feb 23, 2011
    Posts:
    119
    How i do this friend ? with this type off Input.GetMouseButtonDown or another
     
    Last edited: Feb 24, 2011
  4. robhuhn

    robhuhn

    Joined:
    Jun 21, 2009
    Posts:
    113
    This could help:

    Code (csharp):
    1. if (Input.touchCount > 0)
    2. {
    3.      Touch touch = Input.GetTouch(0);
    4.      yourCode();
    5. }
     
  5. KeepTrying

    KeepTrying

    Joined:
    Feb 23, 2011
    Posts:
    119
    This is my production code___________________________________________

    var textura:Texture2D;
    var texturaover:Texture2D;
    function OnMouseOver () {
    guiTexture.texture=texturaover;
    }
    function OnMouseExit(){
    guiTexture.texture=textura;
    }
    function OnMouseDown(){
    Application.LoadLevel(Application.loadedLevel+1);
    }

    This is the code with the modifications ! _________________________________

    var textura:Texture2D;
    var texturaover:Texture2D;

    if (Input.touchCount > 0)
    {
    Touch touch = Input.GetTouch(0);
    guiTexture.texture=texturaover;
    }

    if (Input.touchCount > 0)
    {
    Touch touch = Input.GetTouch(0);
    guiTexture.texture=textura;
    }

    if (Input.touchCount > 0)
    {
    Touch touch = Input.GetTouch(0);
    Application.LoadLevel(Application.loadedLevel+1);
    }

    ERROR > Assets/codes/nextlevel.js(14,58): UCE0001: ';' expected. Insert a semicolon at the end.


    THANKS FOR YOUR HELP !
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    onmouseover is extremely costly as it does a realtime raycasting.

    thats how you can replicate as well by looking for touches that comply to "i need to check over here" and then and only then do the raycasting
     
  7. KeepTrying

    KeepTrying

    Joined:
    Feb 23, 2011
    Posts:
    119
    I think using raycasting is very very complicated my code is ready to go only i need to learn is how to implement this metod

    if (Input.touchCount > 0)
    {
    Touch touch = Input.GetTouch(0);
    yourCode();
    }

    OnMouse is not compatible with iOS >>>>>>>> Look more of my code with the <damn> OnMouse Events i hate that XD

    var lock:Texture;

    var loadlevel:int;

    private var zoom:boolean=false;

    function OnMouseOver () {
    zoom=true;
    if(transform.localScale.x <= 0.87 renderer.material.mainTexture != lock){
    transform.localScale.x += 0.8 * Time.deltaTime;
    transform.localScale.y += 0.8 * Time.deltaTime;
    }
    }

    function OnMouseExit(){
    zoom=false;
    }

    function OnMouseDown(){
    if(renderer.material.mainTexture != lock){
    Application.LoadLevel(loadlevel);
    }
    }


    function Update(){
    if(!zoom renderer.material.mainTexture != lock){
    if(transform.localScale.x >= 0.25){
    transform.localScale.x -= 0.2 * Time.deltaTime;
    transform.localScale.y -= 0.2 * Time.deltaTime;
    }
    }
    }

    I need to join the function Update with that code ?


    if (Input.touchCount > 0)
    {
    Touch touch = Input.GetTouch(0);
    yourCode();
    }


    Because 2 function Update is not allowed Right ?

     
    Last edited: Feb 24, 2011