• 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
-3
Question by Travis 2 · Nov 18, 2010 at 12:40 PM · if-statements

How do i make two if statements

how do i make two if statements for one set of actions?

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 denewbie · Nov 18, 2010 at 12:45 PM 0
Share

what you mean by one set of actions?

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Proclyon · Nov 18, 2010 at 12:53 PM

It's called nesting.

if (condition1) { if(condition2) { //executes this code when the first condition is true AND the second is true }

 //executes this code when the first condition is true

}

Almost the same as:

if(condition1 && condition2)
{
   //Whether condition 1 is true or not doesn't matter, it only matters now if both conditions are true
   //Making long strands of || && &! |* is called boolean logic
}

Mind you that

if (!false)
{
    //this code will be excuted
}

what matters is the RESULT of the condition

And one more thing.

With all due respect, This question is not a question for the U N I T Y answers community, it's a basic all languages question. Please refrain from polluting the Q&A in the future if you can please. There's a whole load of descriptions just what and what not to post and even more double questions. They all try to achieve a single goal. Good Q&A quality. No more no less. I try the same so don't take it personal.

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 denewbie · Nov 18, 2010 at 01:12 PM 0
Share

Now that you mentioned it I think you ve got a point there... This qn isn't really for the community...

avatar image Proclyon · Nov 18, 2010 at 01:52 PM 0
Share

Good to hear my view backed up on the quality of the Q&A process. Thanks

avatar image
1

Answer by denewbie · Nov 18, 2010 at 12:53 PM

Anyway, hers some stuff you can follow:

var a:int = 1;
var b:int = 2;
var c:int =3;

Heres an example of a standard if-else:

if (1 == a)
{
             // Do a set of actions
}
else
{
             // Do another set of actions
}

Here's an example of multiple if-else statements:

if (1 == a)
{
             // Do a set of actions
}
else if (2 -- b)
{
             // Do another set of actions
}
else
{
             // Do YET another set of actions
}

Here's an example of a nested "if":

if (1 == a)
 {
     if (2 ==b)
      {
             // Do a set of actions
      }
}
Comment
Add comment · 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
0

Answer by oliver-jones · Nov 18, 2010 at 02:05 PM

Simple:

Var EyeColour = "Brown"; Var HairColour = "Blonde";

if(EyeColour == "Brown") //Which it does, so its going to return true { if(HairColour == "Pink") // Which it doesn't thus going to return false { print("Hair Colour is Pink"); } else if(HairColour == "Blonde") // Which is true { print("Hair Colour is blonde"); } } else { print("Eye Colour is not Brown"); }

Note: Because eye colour is Brown, it will return value of 'true', so when I ask javascript if EyeColour == "Brown" its going to check to see if it is, and if it is true, it will then ask about the hair colour.

Hair colour does NOT = pink, therefore anything within that if statement will be ignored, thus it will not print "Hair Colour is Pink", however, it will print "hair colour is blonde" simply because that if statement is true.

Another thing to remember is that, if the EyeColour did not equal brown, then none of this if statement will be called and it will go to the else statement and print "Eye Colour is not Brown".

(Colour = Color, I'm British)

--- Edit ---

This is basic JavaScript, I would advise you begin learning JavaScript before you dive into Unity

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 gameplay4all · May 07, 2013 at 09:06 PM 0
Share

how do you type those two vertical lines? e.g: if(Condition1 /dubble line / Condition2){} like an "if or if this" statement

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Problem comparing contents of arrays 1 Answer

Unity GUI Style with if Statements 1 Answer

Double If condition syntax ? 1 Answer

Is there a reason GetKeyDown doesn't work with this code but GetKey does? 1 Answer

Help! Hiding/showing GUITextures! 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges