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 Michael 37 · May 10, 2011 at 03:24 PM · mathscreen-coordinates

Using the Math class and the x/y/z coordinates of models.

I'm working in C# in Unity3D. I want to be able to use the Math class and the functions it has , particularly the absolute value function/Math.Abs , but when I try to import the Math class by typing: "using System.Math" it does not work and says that 'System.Math' is not a namespace.

Another issue I am having is keeping track of the coordinates of the player and the enemy models on screen. I come from an ActionScript background so normally I would simply be able to use "this.x" "objectName.x" and similar pieces of code. However, this doesn't appear to be the same for C#/Unity. Is there a way to directly access the coordinates of an object? I tried using this.x, gameObject.position.x, but that doesn't work.

Thanks.

Comment
Add comment · Show 1
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 DaveA · May 10, 2011 at 03:25 PM 0
Share

These are two separate questions and should be in separate Questions

3 Replies

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

Answer by Eric5h5 · May 10, 2011 at 04:13 PM

Interestingly, this works with JS:

import System.Math;
print (Abs(-5));

However, you don't actually need to import anything to use it, that just makes it more convenient. This works in JS and C#:

print (System.Math.Abs(-5));

You can always just use Unity's Mathf class, though there are some things in System.Math that aren't in Mathf, and also I don't consider Mathf.Sign to have the correct behavior, and prefer to use System.Math.Sign instead.

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 Jessy · May 10, 2011 at 05:44 PM 0
Share

Always thought that was goofy; much better alternative. Why does Unity bother with duplication of these functions?

avatar image Eric5h5 · May 10, 2011 at 06:26 PM 0
Share

Good question. At least they're in the docs, though, so people who are unaware of $$anonymous$$ono/.NET can find them.

avatar image
1

Answer by DaveA · May 10, 2011 at 03:27 PM

transform.position.x Have you looked at the scripting reference at all? It's very helpful: http://unity3d.com/support/documentation/ScriptReference/index.html

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
1

Answer by Aldwoni_legacy · May 10, 2011 at 03:29 PM

Use Mathf.Abs

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

No one has followed this question yet.

Related Questions

Y Rotation mousecoords and object rotation 1 Answer

Convert from m/s to m/fixedFrame 1 Answer

faulty randomness (uniform RNG) 0 Answers

Quaternion using global values instead of local. Please help :( 0 Answers

Why does this simple calculation not show decimals? 1 Answer


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