- Home /
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...".
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"))
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.
You need to place it inside Update() and I don't think it will work if you pause the game in the editor.
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;
}
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" ))
yes, since you were checking for the tags twice.
And added the Input.GetAxis for the "Right Ctrl"
Your answer
Follow this Question
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