using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; /* 准心对象 */ public class CrossHair : MonoBehaviour { public static CrossHair ins; private Image image = null; private bool open = false; private bool visiable = false; void Awake() { ins = this; } void Start() { this.image = this.GetComponent(); this.open = UserSettings.ins.openCrossHair; this.visiable = this.image.enabled; this.SetVisiable(false); } void Update() { if (open) SetVisiable(ArmBow.ins && ArmBow.ins.IsCanShoot()); } void SetVisiable(bool value) { if (this.visiable == value) return; this.visiable = value; this.GetComponent().enabled = this.visiable; } public void SetOpen(bool open) { this.open = open; if (!this.open) { SetVisiable(false); } } public bool GetOpen() { return this.open; } public RaycastHit GetRaycastHit() { float maxDistance = 100; int layerMask = 1 << 8; RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(this.transform.position, Camera.MonoOrStereoscopicEye.Mono); bool raycastResult = Physics.Raycast(ray.origin, ray.direction, out hit, maxDistance, layerMask); // if (raycastResult) return hit.point; return hit; } }