Here yuh go, I made a fancy little joystick for uGUI. uGUI Joystick Example Package (Unity 5.3.4f1) uGUI Joystick Example Package (Old Unity 5.0.0 version) If you don't want to download the example here are the script and image. Joystick.cs
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()
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?
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.
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)
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.
I'm not sure if it's a uGUI problem or not but no it doesn't work with multi-touch at the moment. The multi-touch problem may be fixed in an update later though... http://forum.unity3d.com/threads/ugui-multitouch-win7-not-supported.267164/
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>
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
Thanks for catching that! I've wrapped it in Code (csharp): #if UNITY_EDITOR #endif so you won't have to remove it.
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.
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
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): public void Rotate(Vector2 joystickInput){ transform.Rotate(0,joystickInput.x,0); }
@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!
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.
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!