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 JSierraAKAMC · Jul 14, 2017 at 08:50 AM · c#input

Function Requires Two Button Presses Instead of One?

I'm working on something with the Oculus Rift as a personal project. Everything has been working fine up until this point. The problem is that with my code, a certain function requires two button presses to complete for some reason. However, I know that the functions are being called the first time, because updates to the UI are made. This portion of code deals with the locking and unlocking of objects in a given position. There are UI Toggles that control the locking of separate objects, and the Y and B buttons lock (and unlock) all objects on the respective hand. The code should read as follows:

If the Y button is pressed, check to see if there are any locked objects in the hand. If so, unlock all objects. Otherwise, if the hand trigger is held to a certain degree while the button is pressed, then lock all objects.

In the unlock function, the objects are sorted through and all are unlocked. Then, a call to a static function in the UI manager is made (and again, this updates the first time the button is pressed). However, both in the inspector and in the game, the objects are shown as still being locked. It requires a second press to unlock the objects. Here's the code.

 public void Update(){
 ///....
 if(GetButtonDown(1)){ //Refers to the top button on Oculus Touch controller
             if(AnyLocked()){
                 UnlockObjects();
             } else if(GetHandTrigger() >= 0.95f){
                 LockObjects();
             }
         }
 ///....
 UpdateObjects();
 }
 
 public bool AnyLocked(){
         for(int i = 0; i < objs.Length; i++){
             if(objs[i].locked)
                 return true;
         }
         return false;
     }
 public void LockObjects(){
         for(int i = 0; i < objs.Length; i++){
             objs[i].locked = true;
             string str = ((leftHand)?"L1":"R1") + "C" + (i+1).ToString();
             UIHandler.SetToggleByName(str, false);
         }
     }
     public void UnlockObjects(){
         for(int i = 0; i < objs.Length; i++){
             objs[i].locked = false;
             string str = ((leftHand)?"L1":"R1") + "C" + (i+1).ToString();
             UIHandler.SetToggleByName(str, true);
         }
     }

Is there a logical fallacy I'm missing here? The objects are updated every frame, and putting the UpdateObjects() function at the end of the locking and unlocking functions does nothing.

Any help would be appreciated!

Comment
Add comment · Show 2
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 Bieere · Jul 14, 2017 at 01:36 PM 1
Share

It would be very helpful to see all the code to walk through all the steps, because based on what you've provided so far it should all function correctly. Seeing the function that gets called twice, and what UpdateObject() does could point in the right direction

avatar image JSierraAKAMC · Jul 14, 2017 at 05:12 PM 0
Share

Well, the thing is, the output of the function works the first time, but the locked variable is not changed. I tried placing a Debug.Log in before and after it was changed, and it says the locked variable has been changed, but that change is not shown in the inspector or in-game. $$anonymous$$y guess is the locked variable is changed back somehow before UpdateObjects() is called, but I can't figure out how. The UI should change with the locked variable.

1 Reply

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

Answer by JSierraAKAMC · Jul 15, 2017 at 01:56 AM

Ah, I forgot that I added an 'On Value Changed' event to the UI toggles, so they'd toggle the objects' lock again after disabling it. Oops.

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

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to prevent an animation from triggering more than on due to fast clicking? 2 Answers

Getting the text from UIInput 1 Answer

Projection to mouse position in isometric game 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