Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Joystick

Discussion in 'UGUI & TextMesh Pro' started by GibTreaty, Sep 5, 2014.

  1. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792

    Attached Files:

    Last edited: Jun 1, 2016
  2. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    3,149
    This is awesome. However, have you been able to get it working on mobile? When I add it to my build (And I've tested it works fine w/o it in the build), trying to get the demo scene to work via mobile, I get an error when building the project.


    GC_DONT_GC = 'yes please'
    Apple_Ubiquity_Message = '/tmp/launch-xboSk2/Apple_Ubiquity_Message'
    SHELL = '/bin/bash'
    __CF_USER_TEXT_ENCODING = '0x1F5:0:0'
    GAC_PATH = '/Users/andrew/Space Shooter/Temp/StagingArea/Data/Managed'
    HOME = '/Users/andrew'
    COMMAND_MODE = 'unix2003'
    result file exists: True. Timed out: False
    stdout:
    stderr:

    at UnityEditor.MonoProcessUtility.RunMonoProcess (System.Diagnostics.Process process, System.String name, System.String resultingFile) [0x00000] in <filename unknown>:0
    at UnityEditor.MonoCrossCompile.CrossCompileAOT (BuildTarget target, System.String crossCompilerAbsolutePath, System.String assembliesAbsoluteDirectory, CrossCompileOptions crossCompileOptions, System.String input, System.String output, System.String additionalOptions) [0x00000] in <filename unknown>:0
    at UnityEditor.MonoCrossCompile+JobCompileAOT.ThreadPoolCallback (System.Object threadContext) [0x00000] in <filename unknown>:0
    UnityEditor.HostView:OnGUI()
     
  3. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    I haven't tested it on mobile as I do not have any to test on :(
    I was hoping by putting the code up here that someone who DID have one could test it, just forgot to mention that part. From the looks of the error, I can't see anything that shows that my code is what's causing it.Maybe someone here else could solve what's going on.

    It shows at the very bottom that there is possibly a problem in an OnGUI function, which my code isn't using. Do you have any OnGUI stuff going on?
     
  4. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    3,149
    I don't that I know of, I'm trying to do this all with ugui instead of reverting back to older methods. I'm attempting to rewrite this in unity script as my c# is sparse. Slow going, though, since the docs on 4.6 are limited.
     
  5. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    You know what, I just realized my dad has a tablet. I'll see if I can borrow it later to test on.
     
  6. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    I tested it on the tablet but had some problems. It's a Windows 8 (not RT) tablet.
    • Couldn't see uGUI or pretty much anything else. 3D objects were black and everything else was gray.
    • I could still touch the joystick and move them around but could only touch one at a time
    • No errors (Script Debugging was on)
     
  7. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    3,149
    Interesting -- I added it to my current (pretty small) project, but it wouldn't compile to iOS. It worked when I removed it. I'll try to remember to test it solo to see if it's just an issue w/ something else in the project.
     
  8. PradeepKulasekaran

    PradeepKulasekaran

    Joined:
    Feb 20, 2014
    Posts:
    7
    Does it work with Multi Touch? One touch for JoyStick and another for Shoot button?
     
  9. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
  10. podperson

    podperson

    Joined:
    Jun 6, 2006
    Posts:
    1,371
    They've only been working on this since 2011, you can't expect them to have dealt with obscure problems like virtual joysticks or multitouch. </sarcasm>
     
  11. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    I put the Joystick.cs on the gist part of github. It looks like that's where I should've put it to begin with but I'm a github noob, don't hurt me ;)
     
  12. sdf

    sdf

    Joined:
    Sep 6, 2012
    Posts:
    13
    The touch Zone is a rect,not a circle.how to......?
     
  13. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    As of right now I'm not quite sure but I think there is a way.
     
  14. PrisedRabbit

    PrisedRabbit

    Joined:
    Aug 14, 2012
    Posts:
    62
    To build on iOS just remove OnValidate() method. Thanks for the script!
     
    GibTreaty likes this.
  15. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    Thanks for catching that! I've wrapped it in
    Code (csharp):
    1.  
    2. #if UNITY_EDITOR
    3. #endif
    4.  
    so you won't have to remove it.
     
  16. Shefich

    Shefich

    Joined:
    May 23, 2013
    Posts:
    143
    In my Unity 4.6.1 there are some errors in script:
    - "EventSystemManager.currentSystem" - change to: "EventSystem.current"
    - `UnityEngine.RenderMode' does not contain a definition for `Overlay'. Here I just changed it to ScreenSpaceOverlay.
    I attached joystick script to Image UI. Tell me if I'm wrong, but I also have some visual bugs when move joystick.
     
  17. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    Thanks, updated it (the script and the example package)! Also noted in the tooltip for the joystick graphic that it needs to be a child of the GameObject that the Joystick script is on.

    Joystick
    • Background (optional)
    • Graphic
     
  18. Shefich

    Shefich

    Joined:
    May 23, 2013
    Posts:
    143
    Thanks, I already founded the right order in your example scene.
     
    GibTreaty likes this.
  19. ChanMOOOOR

    ChanMOOOOR

    Joined:
    May 7, 2014
    Posts:
    10
    I have to say your script is more smooth than mine. Thanks!!! Very useful
     
    GibTreaty likes this.
  20. musheer

    musheer

    Joined:
    Jun 17, 2015
    Posts:
    9
    Hiii
    Can we also rotate a character on y axis. Please help
     
  21. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    You can but you'll need to create a function in a script that gets input from the Joystick and uses it for rotation.

    Code (csharp):
    1. public void Rotate(Vector2 joystickInput){
    2.     transform.Rotate(0,joystickInput.x,0);
    3. }
     
    musheer likes this.
  22. Noxury

    Noxury

    Joined:
    Mar 8, 2015
    Posts:
    22
    @GibTreaty
    Hey I get an error when I want to build the game.

    Assets/Plugins/Joystick.cs(128,41): error CS0115: `UnityEngine.UI.Joystick.OnValidate()' is marked as an override but no suitable method found to override

    It has worked on 5.1 though. I am using now 5.3.4f1. It seems like the unity libraries references are moved to other directories / their names changed.

    Please can you update the script?

    Thanks in advance!
     
    GibTreaty likes this.
  23. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    Fixed!



    Just wrapped OnValidate with what's on lines 130 and 135 and it builds out properly now. Edited the github script and uploaded a new example package but had to use 5.3.4f1 since I don't have 5.0.0 installed anymore.
     
    Noxury likes this.
  24. Noxury

    Noxury

    Joined:
    Mar 8, 2015
    Posts:
    22
    Yeah I know these preprocessor defines, but thought that excluding OnValidate will not get the Joystick-script to work in the Build or something else was wrong because like I said it has worked fine on previous versions.

    Thank you for keeping your script Up-To-Date! ;)
     
    GibTreaty likes this.
  25. Deleted User

    Deleted User

    Guest

    Awesome! It worked, Thank You! :)
     
    GibTreaty likes this.