| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class CrossHairOutBoundChecker : MonoBehaviour
- {
- [SerializeField] GameObject outTip;
- string[] tips = {
- "瞄准方向已超出视野范围,请将弓往右移动!",
- "瞄准方向已超出视野范围,请将弓往左移动!",
- "瞄准方向已超出视野范围,请将弓往下移动!",
- "瞄准方向已超出视野范围,请将弓往上移动!",
- };
- int tipIndex = -1;
- void Update()
- {
- Rect pr = CrossHair.ins.parentRTF.rect;
- Vector3 lp = CrossHair.ins.transform.localPosition;
- int newTipIndex = -1;
- if (lp.x < -pr.width / 2) {
- newTipIndex = 0;
- } else if (lp.x > pr.width / 2) {
- newTipIndex = 1;
- } else if (lp.y > pr.height / 2) {
- newTipIndex = 2;
- } else if (lp.y < -pr.height / 2) {
- newTipIndex = 3;
- }
- if (newTipIndex != tipIndex) {
- tipIndex = newTipIndex;
- if (tipIndex >= 0) {
- outTip.GetComponent<Text>().text = tips[tipIndex];
- }
- }
- if (newTipIndex >= 0) {
- if (!outTip.activeSelf) outTip.SetActive(true);
- } else {
- if (outTip.activeSelf) outTip.SetActive(false);
- }
- }
- }
|