Created
June 23, 2019 00:40
-
-
Save bfollington/b1cd795cd6c016690854638eb9190495 to your computer and use it in GitHub Desktop.
Isometric mouse cursor snapping
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
void Update() | |
{ | |
RaycastHit hit; | |
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); | |
if (Physics.Raycast(ray, out hit, 100, FloorLayer)) { | |
Transform objectHit = hit.transform; | |
if (SnapToGrid) { | |
var newPos = new Vector3(Round(hit.point.x, GridSize), _yOffset, Round(hit.point.z, GridSize)); | |
if (_targetPosition != newPos) { | |
Tween.Position(transform, newPos, TweenSpeed, _yOffset, Tween.EaseOut); | |
_targetPosition = newPos; | |
} | |
} else { | |
transform.position = new Vector3(hit.point.x, _yOffset, hit.point.z); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment