Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 AndreasX12 · Jul 02, 2013 at 12:12 PM · floatintnumbernegative

Convert positive float to negative?

Hello :-) How can I convert a positive float to a negative float in C#?

Thanks, Andreas :-)

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

5 Replies

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

Answer by Dave-Carlile · Jul 02, 2013 at 12:13 PM

 x = -x;

Comment
Add comment · Show 4 · 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 AndreasX12 · Jul 02, 2013 at 12:16 PM 0
Share

Thank you :-) Works perfectly and simple :D

avatar image kolboch · Nov 07, 2018 at 09:56 PM 1
Share

Nothing personal but what's the point helping with such questions. How can people with absolutely ZERO program$$anonymous$$g background be making games?! Should not we expect at least $$anonymous$$imum quality???

avatar image AndreasX12 kolboch · Nov 07, 2018 at 10:44 PM 2
Share

I agree. As I look back on this, I could probably have answered this myself or found the answer elsewhere. However, I had no knowledge of program$$anonymous$$g.. Thanks to this forum, I have become a lot smarter (also with the help from see$$anonymous$$gly self-explanatory questions like this).

avatar image kolboch AndreasX12 · Nov 08, 2018 at 11:50 PM 0
Share

Yeah man Do not give up. I just have some triggers. Sry for that. ;) Happy coding.

avatar image
8

Answer by spoilerdo · Apr 02, 2017 at 03:54 PM

 x = -Mathf.Abs(x);
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 wlwl2 · Nov 07, 2018 at 09:04 PM 0
Share

I got a warning because of floatSpeed = +floatSpeed from a unity tutorial, it says that it is assigning the same variable to itself. x = +$$anonymous$$athf.Abs(x); resolves this warning, so thanks. I'm aware that this might not the best solution, but I need to move on.

avatar image
4

Answer by SkyreGames · Jul 02, 2013 at 12:33 PM

Do you remember this from school?

 1*1=1
 -1*-1=1 
 1*-1=-1
 -1*1=-1
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 AndreasX12 · Jul 02, 2013 at 12:35 PM 0
Share

Hehe no ;) I'm only 14, buuuuut I have managed to get a 3D game on Google Play with my little knowlegde about math, hehe ;)

avatar image LoungeKatt · Aug 04, 2015 at 12:34 AM 0
Share

@SkyreGames I take it in your village they don't have to worry about whether or not the language / compiler supports implying the operation without writing it verbatim.

avatar image
0

Answer by M4R5 · Jul 25, 2014 at 04:52 AM

Mathf.Abs for absolute value also works on a variable.

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 $$anonymous$$ · Aug 18, 2019 at 10:11 AM

x = 10;

print(-x);

prints: "-10"

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

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

Related Questions

Checking number against boolean 2 Answers

Change a float smooth 2 Answers

Display a float number when button is clicked 4 Answers

Unity3D editor not allowing large floats as input 1 Answer

int conversion gives bad results ! 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