CrossHairOutBoundChecker.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. /* 检测器-检测游戏射击准心是否出屏幕边界 */
  6. public class CrossHairOutBoundChecker : MonoBehaviour
  7. {
  8. [SerializeField] GameObject outTip;
  9. string[] tips = null;
  10. int tipIndex = -1;
  11. void Start() {
  12. tips = new string[]{
  13. "瞄准方向已超出视野范围,请将弓往右移动!",
  14. "瞄准方向已超出视野范围,请将弓往左移动!",
  15. "瞄准方向已超出视野范围,请将弓往下移动!",
  16. "瞄准方向已超出视野范围,请将弓往上移动!",
  17. };
  18. }
  19. void Update()
  20. {
  21. int newTipIndex = -1;
  22. if (BowCamera.ins && BowCamera.ins.bowCameraFixed != null) {
  23. newTipIndex = BowCamera.ins.bowCameraFixed.outBoundIndex;
  24. }
  25. if (newTipIndex != tipIndex) {
  26. tipIndex = newTipIndex;
  27. if (tipIndex >= 0) {
  28. outTip.GetComponent<Text>().text = tips[tipIndex];
  29. }
  30. }
  31. if (newTipIndex >= 0) {
  32. if (!outTip.activeSelf) outTip.SetActive(true);
  33. } else {
  34. if (outTip.activeSelf) outTip.SetActive(false);
  35. }
  36. }
  37. }