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 hassanF15 · Nov 26, 2014 at 05:49 PM · debug.log

Script / Debug.log question

I want to know how to use Debug.log in If statement

and thats all :/ cause im trying to use console in If statement with Debug.log if u didnt understand i mean this




  1. If (// what to put in here? i want to put debug.log (3) but it doesnt work) {

  2. Destroy(this.gameobject);

  3. }

Comment
Add comment · Show 5
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 tw1st3d · Nov 26, 2014 at 05:58 PM 1
Share

What possible use could that have? Debug.Log() is a void method, meaning it will not return anything.

In order to use an if statement, a method must return either a boolean, float, double, or int value.

Example: if(TurnToNumber("1")) would be true, as 1 in an integer if check results as a true statement.

Example: if(TurnToNumber("0")) would be false, as 0 in an integer if check results as a false statement.

Example: if(GameIsOn()) would be a boolean value, true or false.

avatar image Landern · Nov 26, 2014 at 06:05 PM 0
Share

In order to use an if statement, a method must return either a boolean, float, double, or int value.

@tw1st3d, incorrect, an if statement is based off a boolean expression.

$$anonymous$$SDN IF/ELSE

avatar image tw1st3d · Nov 26, 2014 at 06:08 PM 0
Share

Go type if(1) Debug.Log(true) into a file and see what happens, buddy.

avatar image Landern · Nov 26, 2014 at 06:11 PM 0
Share

Go type if(1) Debug.Log(true) into a file and see what happens, buddy.

Aren't you sweet. In c# 1 can represent true and 0 false... this makes sense as it represent a boolean value(or a bit). However, stating:

In order to use an if statement, a method must return either a boolean, float, double, or int value.

Is 100% incorrect.

But interestingly enough, Boolean.TryParse will fail on conversion of "1", "0" and "-1", but thats converting a string.

And a screenshot: How ODD

And to use an if statement you don't have to use a method, you could just say if (1 < 0) which would be false, no method used.

alt text

numbersasbooleanexpression.png (20.5 kB)
numbersasbooleanexpressionasmethods.png (23.1 kB)
avatar image hassanF15 · Nov 26, 2014 at 06:16 PM 0
Share

Thx tw1st3d , thx Landern :) i know what to do now

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Landern · Nov 26, 2014 at 06:01 PM

An if statement use evaluate to either true or false.

 if (gameObject != null)
 {
   Debug.Log("The gameObject is NOT null");
 }
 else
 {
   Debug.Log("The gameObject IS null");
 }
 
 if (score > highscore)
 {
   Debug.Log("The current score is higher then the highscore... you win!");
 }
 else
 {
   Debug.Log("The current score is NOT higher then the highscore... you win!");
 }
 
 if (gameObject.Name == "Tommy")
 {
   Debug.Log("The gameObject.Name IS equal to \"Tommy\""); // escape characters to display double quotes in string instead of terminating it.
 }
 else
 {
   Debug.Log("The gameObject.Name IS NOT equal to \"Tommy\""); // escape characters to display double quotes in string instead of terminating it.
 }

Debug.Log actually doesn't return anything, it returns void.. nadda.

Now if you want to evaluate something then use the debug.log to display something, that is different, but that's not what you asked.

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Debug.Log is causing an Assert 2 Answers

How does Unity editor communicate with MonoDevelop on OSX? 0 Answers

Log debug message in Xcode's Devices Console 0 Answers

How would I show the value of a random value? 1 Answer

timer that continues through all scences 3 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