CrossHair.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class CrossHair : MonoBehaviour
  6. {
  7. public static CrossHair ins;
  8. private Image image = null;
  9. private bool open = false;
  10. private bool visiable = false;
  11. void Awake()
  12. {
  13. ins = this;
  14. }
  15. void Start()
  16. {
  17. this.image = this.GetComponent<Image>();
  18. this.open = LoginMgr.myUserInfo.openCrossHair;
  19. this.visiable = this.image.enabled;
  20. this.SetVisiable(false);
  21. }
  22. void Update()
  23. {
  24. if (open) SetVisiable(ArmBow.ins && ArmBow.ins.NeedCrossHair());
  25. }
  26. void SetVisiable(bool value)
  27. {
  28. if (this.visiable == value) return;
  29. this.visiable = value;
  30. this.GetComponent<Image>().enabled = this.visiable;
  31. }
  32. public RaycastHit GetRaycastHit() {
  33. float maxDistance = 100;
  34. int layerMask = 1 << 8;
  35. RaycastHit hit;
  36. Ray ray = Camera.main.ScreenPointToRay(this.transform.position, Camera.MonoOrStereoscopicEye.Mono);
  37. bool raycastResult = Physics.Raycast(ray.origin, ray.direction, out hit, maxDistance, layerMask);
  38. // if (raycastResult) return hit.point;
  39. return hit;
  40. }
  41. }