RaycasHitManager.cs 606 B

12345678910111213141516171819202122232425
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class RaycasHitManager : MonoBehaviour
  5. {
  6. // Start is called before the first frame update
  7. void Start()
  8. {
  9. }
  10. // Update is called once per frame
  11. void Update()
  12. {
  13. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  14. Debug.DrawRay(ray.origin, ray.direction, Color.red);
  15. RaycastHit hit;
  16. if (Physics.Raycast(ray, out hit, int.MaxValue, 1 << LayerMask.NameToLayer("layername")))
  17. {
  18. Debug.Log("检测到物体");
  19. }
  20. }
  21. }