Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by D3VEST8R · Apr 25, 2017 at 02:42 PM · errorif-statements

Greater than or less than if statments

I don't understand why this doesn't work

var timer1; var holdtime; if (Input.GetKeyUp(KeyCode.W) && timer1 > holdtime) {}

Unity keeps telling me that I cant use this symbol (>) between the object and the float. Also I wouldn't mind making it a greater than or equal to rather than just greater than if that is possible. I know this is a noobie question but I am new and cant find any answers.

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

2 Replies

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

Answer by UnityCoach · Apr 29, 2017 at 05:34 PM

I'm surprised you can use var without assigning it any value. Like @FortisVenaliter said, type your variables, it'll make it easier. You can use >= or <= for greater/less than or equal to.

 float timer1;
 float holdtime;
 if (Input.GetKeyUp(KeyCode.W) && timer1 >= holdtime)

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 D3VEST8R · May 05, 2017 at 01:16 AM 0
Share

Thank you! I think the problem is fixed now... time to fix the other 1000 problems.

avatar image UnityCoach D3VEST8R · May 05, 2017 at 11:35 AM 0
Share

I know what you mean :) If you're interested and have time, check out my website and subscribe to my newsletter, I'm about to release a new series of training videos on Unity touching on hot topics.

avatar image
1

Answer by FortisVenaliter · Apr 25, 2017 at 02:44 PM

If you're using C# (and it looks like you are), I recommend exorcising the 'var' keyword from your code. When 'var' is forbidden, code is much easier to debug, in my experience. Strong-typed languages can save you headaches!

Also, make sure to initialize your variables. Rather than just declaring them, give them a starting value, even if it's just zero. It increases code readability.

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 ModLunar · Dec 21, 2018 at 11:40 PM 0
Share

Thank you so much for saying this, --- incredibly important to maintain good code! Using 'var' is an abo$$anonymous$$ation in my opinion, haha! XD

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

if statements with no error when script not found 0 Answers

Enumaration error CS1025: Single-line comment or end-of-line expected 1 Answer

can anyone help me out what is wrong with this code? 1 Answer

If statement not working correctly 1 Answer

How apply something like the "!" Operator to an enum? 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