Create Entrance level
This commit is contained in:
24
Assets/Scripts/Utils/LockToGrid.cs
Normal file
24
Assets/Scripts/Utils/LockToGrid.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class LockToGrid : MonoBehaviour
|
||||
{
|
||||
public int tileSize = 1;
|
||||
public Vector3 tileOffset = Vector3.zero;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(!EditorApplication.isPlaying)
|
||||
{
|
||||
Vector3 currentPosition = transform.position;
|
||||
|
||||
float snappedX = Mathf.Round(currentPosition.x / tileSize) * tileSize + tileOffset.x;
|
||||
float snappedZ = Mathf.Round(currentPosition.z / tileSize) * tileSize + tileOffset.z;
|
||||
|
||||
var snappedPosition = new Vector3(snappedX, currentPosition.y, snappedZ);
|
||||
transform.position = snappedPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user