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 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.

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

Making A 4 Barrel ShotGun! Need Some Help - UPDATE 3 Answers

Timed while loop? 0 Answers

Legacy Animations and Unity 5 - What's The Deal? 1 Answer

Trying to Loop A Function 2 Answers


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