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 Elarith · Aug 24, 2012 at 04:27 AM · buttonfunctionpickupunresponsive

Help with unresponsive function / if statement

Hey everyone, I'm attempting to make my character pick up an object.

The problem I think I'm having is that the function the code to pickup an item is in (onTriggerStay) seems to run half as often as the update function, and therefore, when the player presses the "Interact" button, approximately half the time, the function isn't running, and nothing is listening for the interact button.

Just to clarify, the code works, but only registers half of my button presses.

 function OnTriggerStay(other: Collider)
 {
     if(Input.GetButtonUp("Interact") && other.gameObject.CompareTag("Pickup"))
     {
         print("TriggerTest = "+triggerTest++);
     }
         
 }

Now, I have tried placing this code before and after the functionUpdate, I've tried using GetButtonDown instead of up, I've tried the control key on my keyboard, and an Xbox controller (Two different input methods).

The reason I think the function is only running half the time, is because if I comment out /Input.GetButtonUp("Interact") && / in the if statement, and add a similar counter into the function update, in the log, the function update tends to count up twice for every one time the OnTriggerStay updates . Does anyone know why this would be happening, or what I could do to further troubleshoot my issue?

I made a work around for this yesterday, but even after sleeping on it, I'm still not happy with the result I have achieved (and can see potential complications arising as the project gets more complex).

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 Eric5h5 · Aug 24, 2012 at 04:31 AM

OnTriggerStay runs at the physics framerate (i.e., the same rate as FixedUpdate). You must not use Down or Up events in it, because those events are only true for the single frame in which they are activated, which is fairly likely not to occur during a given physics frame. Down and Up events must only be checked in Update, or an equivalent (such as a coroutine that runs every frame).

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 Elarith · Aug 24, 2012 at 04:54 AM 0
Share

Thank you! Although this doesn't help me figure out what to actually do ins$$anonymous$$d. Obviously in the example above, I'm going about it the wrong way, can you recommend a way to achieve what I am attempting to do?

EDIT: I'm accepting this as correct, because it did answer my original question. I'll need to do more research into how to do it so it works, I guess. Thank you again

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How is calling a function from a button click handled internally? 1 Answer

How do I allow my function to run only once at a time? 1 Answer

Custom Editor Window Nodes Unresponsive Button 1 Answer

How do I make the buttons work on this GUI? 2 Answers

GetButton Problem 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