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 Silicon · Apr 10, 2012 at 05:36 AM · gameobjectsyieldwaitforseconds

GetAxisRaw() Ignoring Second Item

What I have is a list of gameobjects that I have attached to the area. The 3 gameobjects are then able to be "cycled" through by the up and down arrows. The issue I'm having is that the key strokes appear to be too sensitive and the input is skipping over the middle item. I can toggle back and forth between item 1 and item 3 but item 2 only gets selected if I get a magic tap on it. See snippet.

void Update () {

     if(Input.GetAxisRaw("Vertical") > 0.9)
     {
         OnSelected(false, Manager[currentMenuItem],speed);
         currentMenuItem--;
         
         if(currentMenuItem <0)
         {
             currentMenuItem = 0;
             
         }
         
         OnSelected(true, Manager[currentMenuItem],speed);
         Yield();
     }
     else if (Input.GetAxisRaw("Vertical") < -0.9)
     {
         OnSelected(false, Manager[currentMenuItem],speed);
         currentMenuItem++;
                         
         if(currentMenuItem >= Manager.Length)
         {
             currentMenuItem = Manager.Length-1;
         }
         
         OnSelected(true, Manager[currentMenuItem],speed);
         Yield();
     }

 }</pre>

So once I saw this problem, I setup a Yield function to delay it a certain amount of time. In this case, .25f seconds to prevent it skipping over but it does not appear to be working. See the following:

IEnumerator Yield()
    {
        yield return new WaitForSeconds(timedelay);
    }
    

What am I doing wrong here to not get a delay?

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
0
Best Answer

Answer by Kleptomaniac · Apr 10, 2012 at 05:50 AM

Could I try to simplify this for you? It may be that the GetAxisRaw is updating too fast and currentMenuItem is increasing and decreasing too fast. Perhaps try it like this instead?

 void Update () 
 {
     if (Input.GetButtonDown("Vertical")) {
         
         OnSelected(false, Manager[currentMenuItem],speed);
         
         currentMenuItem += (Input.GetAxisRaw("Vertical")) * -1;
         currentMenuItem = Mathf.Clamp(currentMenuItem, 0, (Manager.Length - 1));
         
         OnSelected(true, Manager[currentMenuItem],speed);
     }
 }

Not sure if that will work. :P

Hope that helps, Klep

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 Silicon · Apr 10, 2012 at 02:45 PM 0
Share

That solved it. I definitely could have condensed the code. Glad this works for allow a delay. Everything seems to be running smooth.

avatar image Kleptomaniac · Apr 10, 2012 at 02:46 PM 0
Share

Sweet! I'm starting to get sorta good with C# now, just by answering questions! I love UA! Glad I could help mate! :)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Why Is yield return new WaitForSeconds() not working 2 Answers

Definition of Script.function() depends on Script.function()... 3 Answers

About removing the backlight of a button after a set of time 2 Answers

Script gets stuck on WaitForSeconds() 1 Answer

yield WaitForSeconds waits for too long. 2 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