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 KevinRF · Feb 01, 2015 at 05:27 PM · inputbuttoninput.getbutton

Input button

Hello guys. I'm working on a 2d game, i need to create a UI button, for my shooting input

Right now i shoot at " shoot = input.GetButton "Fire1" " "GetButton"to instantly trigger shoot when "Fire1"

i want my Button On pointer down to instantly trigger ("Fire1") when Pointer Is down so i can instant shoot.. .. right now i use this script but it doesn't really work.

using UnityEngine; using UnityEngine.UI; using System.Collections;

public class ShootButton : MonoBehaviour {

 public void Shoot () {
         

      Input.GetButton ("Fire1"); // iam tryin to instantly trigger "Fire1" when Shoot is hold down
     

 }    

}

i hope you guys can help me out

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
1

Answer by Mmmpies · Feb 01, 2015 at 06:28 PM

 Input.GetButton("Fire1");

Will check if the Fire1 button has been pressed but you're talking about a UI. Even then you'd need to tell it what to do next, not just reference it.

I'm going to assume you mean the new UI so let us know if that's not the case. Highlight the button on the canvas and look in the inspector. You'll see a bit that says OnClick, for one click that would be what you'd use but for held down you need to add an event trigger. So...

Click Add Component and add an event trigger. Click "Add New Event Type" and select PointerDown from the list.

Now add a script to the button with a public function that does what you want when firing. This is only an example to send out a Debug.Log statement so you can see the button works, no idea how you want to make your game fire.

 using Unity.Engine;
 using System.Collections;
 
 public class MyFireScript : MonoBehaviour {
 
     public void ImBeingPressed()
     {
         Debug.Log("BANG!!!!");
     }
 }

drag that C# script onto your button and then click the + symbol on the eventTrigger you added. A slot appears so drag your button onto that slot.

Now from the dropdown to the right of where select MyFireScript -> ImBeingPressed

and you should get the Debug.Log message in console.

Comment
Add comment · Show 2 · 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 KevinRF · Feb 02, 2015 at 08:19 PM 0
Share

Hello aim getting the Debug.Log message. but the get.input still not work.. it works on the keyboard so it is not the "Fire1" there is wrong, heres what i did

using UnityEngine; using System.Collections;

public class ShootButton : $$anonymous$$onoBehaviour {

     public void ImBeingPressed()
     {
         
         Debug.Log("BANG!!!!");
         Input.GetButton("Fire1");
     }
 }

what did i do wrong ?

avatar image Mmmpies · Feb 02, 2015 at 08:27 PM 0
Share

You're pressing a UI button and then only doing the Debug.Log and checking if the keyboard is being pressed. Which makes little sense.

What did your code do before using the UI when you just pressed a button. Input.GetButton only checks for the input being pressed it does NOT make something fire even if the button is called Fire1.

EDIT

In fact in $$anonymous$$onoDevelop (assu$$anonymous$$g you use $$anonymous$$ono) click

Search -> Find in Files

and search for

Input.GetButton("Fire1")

As there must be some script that's doing the actual firing if the keyboard works.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Is there a way to do different things depending on whether the button is being held or tapped? 2 Answers

Buttons in input manager don't do anything 1 Answer

How to use Button as Cross Platform Input 0 Answers

NGUI: Button don't detect input if parent change position on-screen? 1 Answer

First button press don't always register after scene load. 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