Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by roncel106 · Jul 02, 2012 at 05:18 PM · androidmobilescreenshootingjoystick

How do I make on screen buttons in Android?

Hi, Technically I'm kinda new at Unity. How do I make 4 buttons to appear at the screen using JavaScript? the first 2 buttons will rotate my character left and right. the other 2 will be for shooting and stuff. May you please explain it to me as simple as possible? on what object will I attach the script?

I'm making an alien shooting game. I use the accelermometer to move my player.

and is it possible to use an image for that certain button. (i want to design how the button looks like in photoshop)

Please Help, Thank you very much and sorry for the bad English. :D

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Luci85 · Jul 03, 2012 at 05:47 PM

The easiest way is to use the standard buttons: http://docs.unity3d.com/Documentation/ScriptReference/GUI.Button.html And script the functionality you want.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by nastasache · Jul 03, 2012 at 10:17 AM

Hi, roncel

The keyword is 'Joystick'. You have a demo scene under Standard assets(mobile), try to play with. The script you can use is named Joystick.js there.

You can use 2 rectangle "Joysticks" (with 'Is touchpad' option checked) for rotating and moving, and 2 "Joysticks" for shooting and stuff. I already have this system working properly,

Of course, you can use your own textures for the joysticks (transparent .png for example), to make these to look as buttons. The option to change texture it's on joystick component options.

Note the joystick positions are relative to the screen (0 to 1 on vertical and horizontal). You can attach the joysticks to a new empty object. I use this kind of object positioned at (0,0,0) in the world space (the difference it's important since the player is moving around and buttons must stay on the screen)

Above joysticks may be used with Javascript in your gameplay rules by capturing tapCount (clicks on) and position (accelerometer values) properties of each joystick.


You can see the joystick if you add texture for it. Size an positions you can change using (in Inspector) Transform position and Pixel Inset values (these are the most important)

The basic steps:

  • Create a PNG texture having (for example) 64x64 pixels; make it semi-transparent; and copy it somewhere under Assets;

  • Create a plane and drag to the scene at (0,0,0)

  • Create a new empty object on the scene, at (0,0,0), rename it to TouchPad

  • Attach the Joystick.js script to the TouchPad object

  • Select TouchPad object in Hierarchy

  • In Inspector:

  • Change the "GuiTexture -> Texture" to your file; your texture will appear on the screen (that's point)

  • Play with "Transform -> Position / Scale" and "Pixel Inset" to see how to change the position on the screen; changing position and size it's related with your texture file size (this is reason I say about example 64x64)

Placing many touchpads require some exercise but finally will see are not so difficult.

You don't need to read, understand and change all Joystick.js script to make touchpads working. Also, on Unity forum already exists some scripts to handle with accelerometer;

I don't know how to upload here a simple package with all you need to see how few touchpads may be used togheter.

Anyway, if you have trouble with touchpads, the Luci85 solution (use standard buttons) it working also.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image roncel106 · Jul 03, 2012 at 05:29 PM 0
Share

lulian, thanks for the help, but how come i can't see the joystick when i put it on play? how can i set how big or small the joystick is and where it is on the screen? how can i set what would that joystick do?

i tried to look at the script of the joystick.js file then my $$anonymous$$d exploded on how long the codes was. if possible, could you help me out more? im still kinda lost.

avatar image rame16 · Jul 21, 2014 at 12:31 PM 0
Share

Hello i'm interested in that start-method. But, what's the point of step "2" , .. create a plane and drag it at (0,0,0) ... ? thanks

avatar image rame16 · Jul 21, 2014 at 02:08 PM 0
Share

Hello i'm interested in that start-method. But, what's the point of step "2" , .. create a plane and drag it at (0,0,0) ... ? thanks

avatar image
0

Answer by Ouss · Jan 25, 2014 at 03:14 PM

You can use the GUI.button to do so. Perhaps I have a problem while using joysticks prefab and button, while using the moving the joystick and press the button, the button doesn't work

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Rohit-Joshi · Jul 16, 2017 at 07:05 AM

In my case, when I deploy the game to Android, the joystick is not visible, but its visible in Unity game mode. Please help me

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GUI Joystick 1 Answer

Mobile Joystick Problem 2 Answers

How to shoot using the right mobile Joystick? 2 Answers

Android C# JoyStick Movement 0 Answers

Making one directional virtual joystick OR smoothly transitioning between buttons 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges