Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
4
Question by coolbudy1998 · Aug 21, 2018 at 07:34 PM · uibuttontouch controlsbuttonstates

How to make the button respond to touch and hold feature?

Hi, I have some UI Buttons in my game. Now they work perfectly when clicked one time. But I want that they should work continuously if the Button is pressed and held for some time. Like, for the Fire Button. Where is change needed, in the script or in the Inspector?? Please help! Thanks!!

Edit - I have tried the two previous answers, but they all doesn't made any difference. thank you for them though.

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

5 Replies

· Add your reply
  • Sort: 
avatar image
9

Answer by LeonmFF · Aug 21, 2018 at 07:48 PM

Hi o/ I'll help you because you're a cool budy.

Go to your button in the Hierarchy, and in the inspector go to "Add Component" -> Event Trigger -> "Add New Event Type" and there you go!

If I'm not mistaken, the event "PointerDown" is the one you want, it's like a "hold event".

The rest is just like OnClick() that you already know your way around it.

Comment
Add comment · Show 1 · 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 coolbudy1998 · Aug 21, 2018 at 09:31 PM 2
Share

haha..yeah it resembles my personality. But this method is also shooting only one time. Thank You for helping though. Even I tried PointerClick, PointerEnter, etc... but they all are working same, one time shoot only.

avatar image
4

Answer by Ahsanhabibrafy · Jul 18, 2020 at 09:15 AM

As I found no solution on the internet I finally came with one. To continuously shoot on Ui Button hold use this script.Add this script in ur Ui ShootButton.` using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems;

 public class ShootHandler : MonoBehaviour,IUpdateSelectedHandler,IPointerDownHandler,IPointerUpHandler
 {
     public bool isPressed;
 
     // Start is called before the first frame update
     public void OnUpdateSelected(BaseEventData data)
     {
         if (isPressed)
         {
          Shoot();
         }
     }
     public void OnPointerDown(PointerEventData data)
     {
         isPressed = true;
     }
     public void OnPointerUp(PointerEventData data)
     {
         isPressed = false;
     }
 }
 
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
1

Answer by HardyForce · Jan 24, 2020 at 06:37 PM

Set a bool to true on PointerDown, and false on PointerUp. Then in your Update function, check if the bool is true before your code executes

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 Vicarian · Aug 21, 2018 at 07:46 PM

I'd use the inspector and add an EventTrigger component, then implement PointerDown. If you're unsure how, visit https://unity3d.com/learn .

Comment
Add comment · Show 1 · 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 coolbudy1998 · Aug 21, 2018 at 09:28 PM 0
Share

Thank You but it is still shooting only one time.

avatar image
0

Answer by venomjadhav · Jul 03, 2020 at 06:12 AM

I think I have a solution. Even my character behaved the same when I tried to move it with buttons, with the PointerDown Event added. I added another one called UpdateSelected. To do that, click "Add New Event Type", and click UpdateSelected. Do your thing by adding the necessary gameobject and panel and you're good to go. Hope it helps.

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

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

Related Questions

How do I highlight multiple buttons at once? 1 Answer

Tapping a button and screen interference 0 Answers

How to change Menu Buttons to a Selected Image and Deselected Image 2 Answers

Buttons on mobile activating OnHighlight Animation without touching them. 0 Answers

Highlighted buttons stay highlighted when I deactivate a canvas. No way to unhighlight them. 1 Answer


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