• 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 JeevanjotSingh · Jun 25, 2015 at 07:06 PM · unity 5errorloopwhilecondition

Add 2 Parameters in While loop

Can anyone please tell me how can i add 2 parameters in while loop in unity 5(I mentioned it because i don't if there is any new rule has cam for unity 5), i want to do something like this :-

 while(attack<=0 && enemy>0)
 {
 
 }

I am trying but it's not working and not giving me the parameter autofill option after && , i think there is something wrong .

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

3 Replies

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

Answer by ZacGarby · Jun 25, 2015 at 08:27 PM

have an "if" inside the while, like this: while ( attack <= 0 ) { if ( enemy > 0 ) { // Do stuff here! } }

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 JeevanjotSingh · Jun 25, 2015 at 08:51 PM 0
Share

Perfect . Thanks , I just skipped that part for my game right now but will use while in next game . :)

It can work with and operator , but i think it maybe disturb in Or condition .

avatar image
2

Answer by Hellium · Jun 25, 2015 at 07:29 PM

Nesting the loops won't have the expected result.

The "parameter" as you call it is a boolean condition (called expression). It's not abnormal to have an expression like this : (attack <= 0 && enemy > 0). It will return a boolean the will statement will evaluate like any other boolean expression.

Just, make sure attack and enemy are numeric values.

What is the error raised by the compiler ?

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 JeevanjotSingh · Jun 25, 2015 at 08:45 PM 0
Share

Yes i know nested will not work - these are symbol errors ,

Assets/whileloop.cs(18,17): error CS1525: Unexpected symbol `}'

Assets/whileloop.cs(21,1): error CS8025: Parsing error

@ZacGarby got the point , thanks to you also @Hellium

avatar image Hellium · Jun 25, 2015 at 08:58 PM 0
Share

I am pretty sure the error didn't come from the while loop then, but just above it.

avatar image
0

Answer by RayJr · Jun 25, 2015 at 07:18 PM

you could try nesting them..

 while(attack<=0 )
 {
    while(enemy>0)
    {
 
    }
 }
 
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 JeevanjotSingh · Jun 25, 2015 at 08:50 PM 0
Share

Very well but it won't give us expected results .

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

23 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 avatar image avatar image

Related Questions

While loop doesn't start again when condition is true 1 Answer

How often does a for loop loop? 1 Answer

Why my unity 5 create-new-project screen became like this? 1 Answer

Animation from Blender 0 Answers

while loop & array- turn on something via percentage 1 Answer

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