CrossHair.cs 734 B

1234567891011121314151617181920212223242526
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class CrossHair : MonoBehaviour
  5. {
  6. // Start is called before the first frame update
  7. public Camera bowCamera;
  8. public static CrossHair ins;
  9. void Start()
  10. {
  11. ins = this;
  12. }
  13. public Vector3 getRayHitPoint() {
  14. RaycastHit hit;
  15. Ray ray = bowCamera.ScreenPointToRay(this.transform.position, Camera.MonoOrStereoscopicEye.Mono);
  16. bool raycastResult = Physics.Raycast(ray.origin, ray.direction, out hit, 60, 1 << 8);
  17. if (raycastResult) {
  18. return hit.point;
  19. } else {
  20. return bowCamera.transform.position + bowCamera.transform.forward * 60;
  21. }
  22. }
  23. }