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 ChrisSch · Aug 20, 2013 at 06:45 AM · ifand||

Simple && and || question.

Hi everyone! So in a script I wrote the code in a way to test the game both on PC and android, and everything works except this part.

It's suppose to check whether right ctrl and up/down are being pressed upon collision with a specific tagged object, or ,if im using the android controls, to check if upClicked and activateClicked are true. The script worked till I mixed it up with the boolean values, and I checked the tags everything is fine.

So here it is.

         var menuOptionsScript : MenuOptions;
         var menuOptions : GameObject;
     
         function Start ()
         {
             menuOptionsScript = menuOptions.gameObject.FindWithTag("MenuOptions").GetComponent(MenuOptions);
         }
 function OnCollisionStay(coll : Collision)
 {
     if((Input.GetAxis("Vertical" && "Right Ctrl") > 0 && (coll.gameObject.tag == "Player" || coll.gameObject.tag == "ShipLoaded" )) || (menuOptionsScript.upClicked && menuOptionsScript.activateClicked) && (coll.gameObject.tag == "Player" || coll.gameObject.tag == "ShipLoaded" ))
     {
     rigidbody.mass = 100;
 }

Its a bit long I know but I wanted to cram it all in one line. xD

The whole thing used to work before continuing it with "||(menuOptionsScript...".

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

Answer by Joyrider · Aug 20, 2013 at 06:49 AM

at the beginning of your if-statement... I think you meant to write

 if(Input.GetAxis("Vertical") && Input.GetAxis("Right Ctrl"))
Comment
Add comment · Show 10 · 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 ChrisSch · Aug 20, 2013 at 06:57 AM 0
Share

No that's not working either. :( It's suppose to change the mass to "rigidbody.mass = 100;" but I paused while holding down ctrl + up/down, and its not changing it.

avatar image Linus · Aug 20, 2013 at 06:59 AM 1
Share

You need to place it inside Update() and I don't think it will work if you pause the game in the editor.

avatar image ChrisSch · Aug 20, 2013 at 07:08 AM 0
Share

Sorry, but place which part inside Update()? It posted the original code wrong I'll edit it. It's suppose to be:

 function OnCollisionStay(coll : Collision)
 {
     if((Input.GetAxis("Vertical" && "Right Ctrl") > 0 && (coll.gameObject.tag == "Player" || coll.gameObject.tag == "ShipLoaded" )) || (menuOptionsScript.upClicked && menuOptionsScript.activateClicked) && (coll.gameObject.tag == "Player" || coll.gameObject.tag == "ShipLoaded" ))
     {
     rigidbody.mass = 100;
 }
avatar image Joyrider · Aug 20, 2013 at 07:34 AM 1
Share

try this, I reordered it somewhat, maybe it is going to help.

 if(((Input.GetAxis("Vertical") && Input.GetAxis("Right Ctrl")) > 0 || (menuOptionsScript.upClicked && menuOptionsScript.activateClicked)) && (coll.gameObject.tag == "Player" || coll.gameObject.tag == "ShipLoaded" ))
avatar image Joyrider · Aug 20, 2013 at 07:51 AM 1
Share

yes, since you were checking for the tags twice.

And added the Input.GetAxis for the "Right Ctrl"

Show more comments

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

17 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

Related Questions

If \ Else how does the program reads it? 2 Answers

Audio problem? "Or" syntax question? 1 Answer

if( ... && ... && ... || ... &&) { reload } 4 Answers

Black and White Visuals? 2 Answers

How to define the number of times of an event? 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