unity-atoms/Source/Extensions/Vector2Extensions.cs
Jeff Campbell 7763f81ede Unified line endings
* 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.
2019-04-07 11:56:54 +02:00

24 lines
600 B
C#

using UnityEngine;
namespace UnityAtoms.Extensions
{
public static class Vector2Extensions
{
public static Vector3 ToVector3(this Vector2 v2, float z = 0f)
{
return new Vector3(v2.x, v2.y, z);
}
public static Vector3 ToWorldPos(this Vector2 v2)
{
return Camera.main.ScreenToWorldPoint(v2);
}
public static Vector2 TowardsTarget(this Vector2 v2, Vector2 target, float maxDistance)
{
var distance = target - v2;
return v2 + (distance.normalized * maxDistance);
}
}
}