Created
January 14, 2022 20:13
-
-
Save farukcan/cc64ff687f513b49ece998e381a3c488 to your computer and use it in GitHub Desktop.
Axis Extension For Unity Engine To Handle Axises Quickly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Author: github.com/farukcan | |
// Usage: | |
// Get vector - AxisExtension.GetVector(Axis.LEFT) | |
// Get direction vector relative to the object - AxisExtension.GetVector(transform,Axis.LEFT) | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public static class AxisExtension | |
{ | |
public enum Axis { UP, DOWN, FORWARD, BACK, LEFT, RIGHT, ZERO }; | |
public static Vector3 GetVector(Axis axis) | |
{ | |
if (axis == Axis.BACK) | |
{ | |
return Vector3.back; | |
} | |
if (axis == Axis.FORWARD) | |
{ | |
return Vector3.forward; | |
} | |
if (axis == Axis.LEFT) | |
{ | |
return Vector3.left; | |
} | |
if (axis == Axis.RIGHT) | |
{ | |
return Vector3.right; | |
} | |
if (axis == Axis.UP) | |
{ | |
return Vector3.up; | |
} | |
if (axis == Axis.DOWN) | |
{ | |
return Vector3.down; | |
} | |
return Vector3.zero; | |
} | |
public static Vector3 GetVector(Transform transform,Axis axis) | |
{ | |
if (axis == Axis.BACK) | |
{ | |
return -transform.forward; | |
} | |
if (axis == Axis.FORWARD) | |
{ | |
return transform.forward; | |
} | |
if (axis == Axis.LEFT) | |
{ | |
return -transform.right; | |
} | |
if (axis == Axis.RIGHT) | |
{ | |
return transform.right; | |
} | |
if (axis == Axis.UP) | |
{ | |
return transform.up; | |
} | |
if (axis == Axis.DOWN) | |
{ | |
return -transform.up; | |
} | |
return Vector3.zero; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment