To use Unity Mathematics, add using Unity.Mathematics to your code:
using static Unity.Mathematics.math;
namespace MyNamespace
{
using Unity.Mathematics;
...
var v1 = float3(1,2,3);
var v2 = float3(4,5,6);
v1 = normalize(v1);
v2 = normalize(v2);
var v3 = dot(v1, v2);
...
}
Naming convention
In C# int and float are built-in types. The Burst compiler extends this set of built-in types to also include vectors, matrices, and quaternions. These types are built-in because the Burst compiler already has implementations of these types, and so can use them to generate better code than for custom types.
To signify that these types are built-in their type names are in all lower case. The operators on these built-in types in Unity.Mathematics.math are intrinsics and are always in lower case.
There are no plans to extend the set of intrinsic types beyond the current set of vectors (typeN), matrices (typeNxN) and quaternions (quaternion).
This convention has the added benefit of making the library highly compatible with shader code and makes porting or sharing code between the two almost frictionless.
Did you find this page useful? Please give it a rating:
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.