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
0
Question by Ineedplay · Jul 18, 2013 at 09:05 AM · androidfpsgui button

How would I use a Gui Button to shoot?

I need help in putting a shoot function for android. I have Gui Button now how would I could so basically my gun would shoot

I just want to replace the "fire1" command which is used to shoot in PC/Mac Fps with pressing a Gui Button.

Could someone please help me out?

Thanks

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by save · Jul 18, 2013 at 09:14 AM

What probably would be best in your case is to break the shooting out to a function. then just call that from either when Input.GetAxis("Shooting") returns true or when your Gui Button is interacted with. A RepeatButton would probably be suitable if you want to check that the button is pressed over several frames. What you need to do as well is to create a separate axis for shooting because Fire1 is automatically called when interacting on iOS and Android. Another way of solving it would be to check Input.GetMouseButton(0) (which in most cases is left mouse button) - but, which would limit the user to not be able to change it in the input configuration.

 function OnGUI () {
     if (GUI.RepeatButton(Rect(10,70,50,30),"Shoot"))
         GoTriggerHappy();
 }

 function Update () {
     if (Input.GetAxis("Shoot"))
         GoTriggerHappy();
 }

 function GoTriggerHappy () {
     // All events for shooting goes here
 }


Comment
Add comment · Show 11 · 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 Ineedplay · Jul 18, 2013 at 09:21 AM 0
Share

So basically I take my gun script and put it on the go trigger happy place? And then put this script on my gui button? But I encountered a problem before the button fire 1 is activated if one finger is touches the screen of the phone how would I disable that and only make it if it touches the button?

avatar image save · Jul 18, 2013 at 09:27 AM 0
Share

Ah yes forgive me, Fire1 is always called upon interaction on iOS and Android. What you need to do is to have a separate name for the input axis to fire or call Input.Get$$anonymous$$ouseButton(0) ins$$anonymous$$d.

I always use Input.Get$$anonymous$$ouseButton(0) because this is in most causes just for testing purposes in the editor where user editing of input buttons isn't a necessary function, then check for interaction with Input.touchCount>0.

I'm not sure what your structure would be with script placements. Try to gather all interaction events under one script where you also have all your references to all GameObjects which in some way is a part of the interaction. It's a classic method to not go crazy after a while. :) Then of course some events must happen outside of that script, but that's usually just a call from your interaction script to a function inside the other script.

avatar image Ineedplay · Jul 18, 2013 at 09:33 AM 0
Share

And so basically replace fire button with get mouse button 0 ? And do what you said?

avatar image Ineedplay · Jul 18, 2013 at 09:33 AM 0
Share

Thank you so much!!! You saved my life :D I will pay you back if I get somewhat famous ;)

avatar image save · Jul 18, 2013 at 09:42 AM 0
Share

Haha no need to, you just have to make great games and I'll play them. :) I updated my previous comment.

Show more comments

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

16 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Mobile FPS Help 0 Answers

Why my game's FPS drop every time I change scene (Android Game) ? 1 Answer

Calling static jar function from Unity3D 0 Answers

constantForce and relativeForce errors. 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