Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 seidensj · Mar 11, 2016 at 03:34 PM · uitoggleonclickoverride

Best way to override OnClick with OnPointerDown for Toggle?

I want to execute a toggle's OnValueChanged method on a OnPointerDown event instead of an OnClick event. Is there an elegant way to do this?

Right now I'm just using an EventTrigger component with a OnPointerDown event on the Toggle GameObject to execute the the method I want, but this gets gross quickly. For one OnClick is still called on the Toggle Component. Yes, I could turn interactable false on the Toggle component, but then this presents the wrong visual state, yada yada yada.

I really just want all the functionality of the toggle, I just want it to be triggered OnPointerDown INSTEAD of OnClick.

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 Lo0NuhtiK · Mar 11, 2016 at 04:29 PM

Make a class that inherits from Toggle and override its stuff...

 using UnityEngine.UI;
 using UnityEngine.EventSystems;
 
 public class MyToggle : Toggle 
 {
      public override void OnPointerClick(PointerEventData eventData)
      {
          //do nothing... we don't want it do do anything OnClick
      }
 
      public override void OnPointerDown(PointerEventData eventData)
      {
           //do the stuff it usually does
           base.OnPointerDown(eventData);
           //do the stuff we want it to do
           base.OnSubmit(eventData);
      }     
 }

Then take the unity toggle component off, put this on, reassign the target graphic etc.

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 8e8618be-a4d5-486a-b998-e6d4a4eb8c8b_DELETE · Feb 16, 2020 at 10:39 AM 0
Share

What do you mean with: "Then take the unity toggle component off, put this on, reassign the target graphic etc.", please explain, I'm new to unity

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Daikon Forge - Close windows when clicking out of bounds 0 Answers

OnClickUpAsButton used externaly 0 Answers

UI button stops working after reload scene 1 Answer

[4.6] Toggle/Checkbox On/Off 1 Answer

Change Scroll bar on click 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