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 Hyperactive · Feb 06, 2015 at 03:08 PM · booleanontriggerstay

Bool changing automatically...

Hi !

Any ideas why my bool goes to true as soon as I press E in my game ?

Just trying to make it so that if the bool is set to true, and the player is in the collider AND he presses E, the collider moves.

But if the bool is on false and I press E, the bool changes to true and the collider moves.

     public float speed = 8f; 
     public bool Up = false;
     
     void OnTriggerStay (Collider other)
         {
         if ((other.gameObject.tag == "Player") && (Input.GetKey(KeyCode.E)) && (Up = true)) 
         transform.Translate(Vector3.up * speed * Time.deltaTime);
         }

Thanks for the help !

Also looking into making a list instead of bools, some basically have a list of Up, Down, Left, Rift. So if Right is selected in the drop down, do this. If Right is selected in the drop down, do that... etc...

Any pointers ? Should I use enums ?

Hyper

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 AngryBurritoCoder · Feb 06, 2015 at 03:41 PM 0
Share

Also just as a tip, you should start variables with lower case character for first word, not required just convention xd

2 Replies

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

Answer by ryandotdee · Feb 06, 2015 at 03:49 PM

Because you are missing an = sign in your conditional

 && (Up = true))
 

should be

 && (Up == true))

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 Hyperactive · Feb 06, 2015 at 03:55 PM 0
Share

Bahaha ! You absolute legend ! :D Well that's what I get for coding all day, can't see anything anymore. Thanks a lot :)

avatar image ryandotdee · Feb 06, 2015 at 03:59 PM 0
Share

No Worries :)

avatar image
1

Answer by AngryBurritoCoder · Feb 06, 2015 at 03:31 PM

Check , maybe it's ticked to true in inspector of the script component in unity editor. Or your changing it in another script

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 Hyperactive · Feb 06, 2015 at 03:46 PM 0
Share

As I said "if the bool is on false and I press E, the bool changes to true and the collider moves."

Which means when I Press E, the bool goes from false to true...

I've tried an empty scene with just that script and my character controller.

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

21 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

Related Questions

OnTriggerStay not working correctly. 0 Answers

How to detect if a function is "happening"? 1 Answer

OnTriggerStay2D changes bool to true and false at the same time. 1 Answer

Problem with OnTriggerStay2D function 2 Answers

Player movement isn't working 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