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 superluigi · Jul 24, 2013 at 11:12 PM · javascriptontriggerenter

function OnTriggerEnter with two conditionals help

This doesn't work. Why?

 function OnTriggerEnter (other : Collider)
     {
     
         if (other.gameObject.name == "LadderTrigger" && Input.GetKeyDown("w"))
         {
             ScriptCamera.enableDynamicCam = true;
         }
     }
Comment
Add comment · Show 1
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 Owen-Reynolds · Jul 24, 2013 at 11:54 PM 0
Share

As BenProd notes, the thing the code actually checks for is probably not what you want.

$$anonymous$$ight help if you describe what you are trying to make happen (player presses a key while they are near a ladder?)

1 Reply

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

Answer by Benproductions1 · Jul 24, 2013 at 11:25 PM

Hello,

The reason this doesn't work, is because Input is frame based. Meaning it works within the Update functions etc...
But OnTriggerXXXX is Physics based, so it uses FixedUpdate, which is independant from the framerate.

There are plenty of examples of how to use Input in FixedUpdate. Use any of those and it should work :)

Another problem you will have, is that you are checking for 2 events, that only ever happen once. Only if you Enter the trigger AND press the button down at the exact same time, will anything happen. The chances anyone will be able to do this are very slim. I suggest either using Input.GetKey or OnTriggerStay

Hope this helps,
Benproductions1

Comment
Add comment · Show 4 · 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 Banholio · Jul 25, 2013 at 12:14 AM 0
Share

I second this, maybe you could put a flag = true during OnTriggerEnter, so that on your update you can check if the flag && Input.Get$$anonymous$$ey conditions are met. Then if OnTriggerExit you can set the flag off.

avatar image superluigi · Jul 25, 2013 at 01:29 AM 0
Share

Ok I see what you mean. I also tried

 if(other.name== "ladderTrigger")
 {
    if()Input.GetkeyDown("w"){
    }
 }

but I suppose that's the same thing.

avatar image Benproductions1 · Jul 25, 2013 at 01:37 AM 0
Share
  1. That won't compile. The brackets need to be around the Input function. if (Input.Get$$anonymous$$eyDown("w"))

  2. Yes it's exactly the same thing,

avatar image Benproductions1 · Jul 25, 2013 at 01:38 AM 0
Share

@Banholio That only works as long as you can only be in one trigger at once. If you can be in more than once, it will fail and bug out. Thats why I prefer OnTriggerStay :)

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

18 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

Related Questions

Trouble with a respawn script 1 Answer

Unity freezes when OnTriggerEnter occurs 3 Answers

OnTriggerEnter not detecting tag 2 Answers

Show message when gameobject hits other gameobject.. 1 Answer

how to stop every thing and enter into the OnTriggerEnter function? 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