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 BrandonSeifker · Jun 19, 2017 at 02:28 PM · guibuttontriggerunity5click

OnTrigger Down, Call the Button's OnClicked event

This is incredibly simple but it's impossible to find any help on it. I have an HTC vive controller and I'd like to call my button's onClicked event (which I set in the buttons inspector) on the triggerDown function. The onClicked event I have set for my button is simply to enable and disable a panel but I can't find any scripts to effectively turn my TriggerDown event into a Click.

Please help.

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

2 Replies

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

Answer by BrandonSeifker · Jun 19, 2017 at 04:30 PM

Answering my own question but here is what Ive found to work

 using UnityEngine; 
 2 using System.Collections; 
 3 using UnityEngine.UI; 
 4 using System; 
 5 
  
 6 public class LaserButtonClicker : MonoBehaviour 
 7 { 
 8     SteamVR_LaserPointer laserPointer; 
 9     Button btn; 
 10     private int deviceIndex = -1; 
 11     private SteamVR_Controller.Device controller; 
 12     bool pointerOnButton = false; 
 13     GameObject myEventSystem; 
 14     // Use this for initialization 
 15     void Start() 
 16     { 
 17         myEventSystem = GameObject.Find("EventSystem"); 
 18         laserPointer = GetComponent<SteamVR_LaserPointer>(); 
 19         laserPointer.PointerIn += LaserPointer_PointerIn; 
 20         laserPointer.PointerOut += LaserPointer_PointerOut; 
 21     } 
 22     private void SetDeviceIndex(int index) 
 23     { 
 24         deviceIndex = index; 
 25         controller = SteamVR_Controller.Input(index); 
 26     } 
 27     private void LaserPointer_PointerOut(object sender, PointerEventArgs e) 
 28     { 
 29 
  
 30         if (btn != null) 
 31         { 
 32             pointerOnButton = false; 
 33             myEventSystem.GetComponent<UnityEngine.EventSystems.EventSystem>().SetSelectedGameObject(null); 
 34             btn = null; 
 35         } 
 36     } 
 37 
  
 38     private void LaserPointer_PointerIn(object sender, PointerEventArgs e) 
 39     { 
 40 
  
 41         if (e.target.gameObject.GetComponent<Button>() != null && btn == null) 
 42         { 
 43 
  
 44             btn = e.target.gameObject.GetComponent<Button>(); 
 45             btn.Select(); 
 46 
  
 47             pointerOnButton = true; 
 48              
 49         } 
 50     } 
 51 
  
 52   void Update() 
 53     { 
 54         if (pointerOnButton) 
 55         { 
 56             if (controller.GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger)) 
 57             { 
 58                 btn.onClick.Invoke(); 
 59             } 
 60         } 
 61     } 
 62      
 63     
 64 
  
 65 
  
 66 } 
 

i got it from this github, you will need to add a rigid body and box collider to your controller as well

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 BrandonSeifker · Jun 19, 2017 at 04:30 PM 0
Share

https://github.com/alkamegames/laser-pointer-button-click-for-htcvive/blob/master/LaserButtonClicker.cs

avatar image
0

Answer by FlaSh-G · Jun 19, 2017 at 03:22 PM

You can invoke any Unity event using UnityEvent.Invoke.

 someButton.onClick.Invoke();
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

134 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

Related Questions

Trigger a Button Click 2 Answers

android and ios - phantom UGUI Button click when loading new scene w/ finger already down 1 Answer

Can't click gameobject when over another trigger? 1 Answer

gui.button down 2 Answers

GUI button to Unity5 Button OnClic function 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