You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.5 KiB
54 lines
1.5 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using UnityEngine.Events; |
|
using UnityEngine.Serialization; |
|
|
|
public class TouchRayHit : MonoBehaviour |
|
{ |
|
public new Camera camera; |
|
public Transform pointer; |
|
|
|
int layerMask; |
|
private void Start() |
|
{ |
|
if (camera == null) |
|
camera = FindObjectOfType<Camera>(); |
|
|
|
//layerMask = 1 << LayerMask.NameToLayer("Wall"); |
|
} |
|
|
|
[System.Serializable] |
|
public class EvRecieveHitPosition : UnityEvent{ } |
|
[FormerlySerializedAs("onEnd")] |
|
[SerializeField] |
|
private EvRecieveHitPosition m_OnEnd = new EvRecieveHitPosition(); |
|
public EvRecieveHitPosition OnTouch |
|
{ |
|
get { return m_OnEnd; } |
|
set { m_OnEnd = value; } |
|
} |
|
|
|
RaycastHit hit; |
|
private void Update() |
|
{ |
|
if (camera != null && Input.GetMouseButtonDown(0)) // 마우스가 클릭 되면 |
|
{ |
|
Ray ray = camera.ScreenPointToRay(Input.mousePosition); |
|
RaycastHit hit; |
|
if (Physics.Raycast(ray, out hit, 1000)) |
|
{ |
|
if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Map")) |
|
{ |
|
Debug.DrawLine(camera.transform.position, hit.point, Color.blue, 1f); |
|
|
|
if (pointer != null) |
|
pointer.position = hit.point; |
|
|
|
if (m_OnEnd != null) |
|
m_OnEnd.Invoke(); |
|
} |
|
} |
|
} |
|
} |
|
}
|
|
|