CirclePoint.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class CirclePoint : MonoBehaviour {
  6. private Image img;
  7. private bool interact;
  8. public Sprite Spr1;
  9. public Sprite Spr2;
  10. // Use this for initialization
  11. void Start () {
  12. img = GetComponent<Image>();
  13. }
  14. // Update is called once per frame
  15. void Update () {
  16. ChangeSprite();
  17. CirclePoint1();
  18. }
  19. void ChangeSprite()
  20. {
  21. Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
  22. RaycastHit hit;
  23. if (Physics.Raycast(ray, out hit))
  24. {
  25. if (hit.collider.tag == "cube" || hit.collider.tag == "floor") //判断碰撞物体的tag,这里是表示可以被交互的物体
  26. {
  27. interact = true;
  28. }
  29. else //不可以被交互的物体
  30. {
  31. interact = false;
  32. }
  33. }
  34. else //没有碰撞体的物体
  35. {
  36. interact = false;
  37. }
  38. }
  39. void CirclePoint1() //准心的放大与缩小动画
  40. {
  41. if (interact)
  42. {
  43. img.sprite = Spr2;
  44. }
  45. else { img.sprite = Spr1;
  46. } //准心不显示
  47. }
  48. }