add grid manager
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Mouse3d : MonoBehaviour
|
||||
{
|
||||
public static Mouse3d Instance { get; private set; }
|
||||
[SerializeField] private LayerMask _mouseColliderLayerMask = new LayerMask();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
_mouseColliderLayerMask = transform.gameObject.layer;
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, 999f, _mouseColliderLayerMask))
|
||||
{
|
||||
transform.position = hit.point;
|
||||
}
|
||||
}
|
||||
public static Vector3 GetMouseWorldPosition() => Instance.GetMouseWorldPosition_Instance();
|
||||
private Vector3 GetMouseWorldPosition_Instance()
|
||||
{
|
||||
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, 999f, _mouseColliderLayerMask))
|
||||
{
|
||||
return hit.point;
|
||||
}
|
||||
return Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user