Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Test : MonoBehaviour
- {
- private Ray _ray;
- private RaycastHit _hit;
- void Update()
- {
- if (Input.GetMouseButton(0))
- {
- Cast();
- }
- }
- private void Cast()
- {
- var mouse = Input.mousePosition;
- mouse.z = Camera.main.nearClipPlane;
- _ray = Camera.main.ScreenPointToRay(mouse);
- if (Physics.Raycast(_ray, out _hit, 200))
- {
- Debug.Log(_hit.transform.name);
- }
- }
- private void OnDrawGizmos()
- {
- Gizmos.color = Color.red;
- Gizmos.DrawRay(_ray.origin, _ray.direction * 200);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement