Search Unity

Code works in Unity5, Unity Remote 4, but not as in .APK

Discussion in 'Scripting' started by MG, Aug 2, 2015.

  1. MG

    MG

    Joined:
    Nov 10, 2012
    Posts:
    190
    I have made a game to for Android. I'm not using any touch input, only void OnMouseDown, because, its only requires one click at the time.

    What i am trying to do:
    When i click on a object, a 2D Circle collider enables, and anyone within this collider shall be destroyed.

    Where is it working?
    When i test the game in unity, and click with the mouse it works perfectly
    When i test the game though Unity Remote 4, with my Samsung Galaxy S6 egde, it works perfectly.

    When i build the game into a .apk, and test it on my same Samsung mobile, it doesn't work anymore.

    Why would there be a different?
     
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Last time I checked, my android didnt come with a mouse.

    Does Android support OnMouseDown... not sure, but I doubt it. Your failed tests somewhat confirm it.
     
  3. MG

    MG

    Joined:
    Nov 10, 2012
    Posts:
    190
    JamesLeeNZ

    OnMouseDown have work so far.
    I have only used OnMouseDown, to the whole game, It works perfect when i navigate though the menu and levels.
    But when it comes to this object it wont work
     
  4. MG

    MG

    Joined:
    Nov 10, 2012
    Posts:
    190
    Okay here is a how it was planned to work.

    Object 1: The Bomb
    Tag: Bomb
    Collider: BoxCollider2D & CircleCollider2D (On trigger and disable at start)
    Action: When you click on the bomb, CircleCollider2D enables

    Object X: The Targets in plural
    tag: unknown
    Collider: BoxCollider2D
    Action:
    Code (CSharp):
    1. void OnTriggerEnter2D( Collider2D hit)
    2.        
    3.     {
    4.         if (hit.gameObject.tag == "Bomb")
    5.            {
    6.             Destroy (gameObject);
    7.             }
    8.         }
    9.     }
    Conclusion: Apperently the trigger function doesn't work properly on my phone.
    Solution: Instead of Trigger on 2D, i went back to the Bomb, Made this:
    Code (CSharp):
    1. void OnTriggerEnter2D (Collider2D hit)
    2.     {
    3.         hit.gameObject.SendMessage ("destroy", SendMessageOptions.DontRequireReceiver);
    4.     }
    So every object who has a function destroy, will be destroyed.

    I dont know if this is the perfect solution, but it works!