Created
March 6, 2024 02:02
-
-
Save baba-s/d88eb1aed831c65586ba9ad80826bd5e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using UnityEngine; | |
public class Example : MonoBehaviour | |
{ | |
private Vector3 m_prevLocalPosition; | |
private enum DirectionType | |
{ | |
NONE, | |
UP, | |
DOWN, | |
LEFT, | |
RIGHT | |
} | |
private void Awake() | |
{ | |
m_prevLocalPosition = transform.localPosition; | |
} | |
private void LateUpdate() | |
{ | |
var movement = transform.localPosition - m_prevLocalPosition; | |
var directionType = | |
0.1f < movement.magnitude | |
? Mathf.Abs( movement.y ) < Mathf.Abs( movement.x ) | |
? 0 < movement.x | |
? DirectionType.RIGHT | |
: DirectionType.LEFT | |
: 0 < movement.y | |
? DirectionType.UP | |
: DirectionType.DOWN | |
: DirectionType.NONE | |
; | |
m_prevLocalPosition = transform.localPosition; | |
Debug.Log( directionType ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment