mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-24 09:08:23 -05:00
7763f81ede
* Unified all line endings in project to align with .editorconfig; all end-of-line characters have been set to LF and new-lines placed at the end of every file if not present.
29 lines
778 B
C#
29 lines
778 B
C#
using UnityEngine;
|
|
|
|
namespace UnityAtoms.Extensions
|
|
{
|
|
public enum V3Axis { x, y, z }
|
|
public static class Vector3Extensions
|
|
{
|
|
public static Vector2 ToVector2(this Vector2 v3)
|
|
{
|
|
return new Vector2(v3.x, v3.y);
|
|
}
|
|
|
|
public static Vector3 TowardsTarget(this Vector3 v3, Vector3 target, float maxDistance)
|
|
{
|
|
var distance = target - v3;
|
|
return v3 + (distance.normalized * maxDistance);
|
|
}
|
|
|
|
public static Vector3 CloneAndChange(this Vector3 v3, V3Axis axis, float val)
|
|
{
|
|
return new Vector3(
|
|
axis == V3Axis.x ? val : v3.x,
|
|
axis == V3Axis.y ? val : v3.y,
|
|
axis == V3Axis.z ? val : v3.z
|
|
);
|
|
}
|
|
}
|
|
}
|