using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class CirclePoint : MonoBehaviour { private Image img; private bool interact; public Sprite Spr1; public Sprite Spr2; // Use this for initialization void Start () { img = GetComponent(); } // Update is called once per frame void Update () { ChangeSprite(); CirclePoint1(); } void ChangeSprite() { Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0)); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.collider.tag == "cube" || hit.collider.tag == "floor") //判断碰撞物体的tag,这里是表示可以被交互的物体 { interact = true; } else //不可以被交互的物体 { interact = false; } } else //没有碰撞体的物体 { interact = false; } } void CirclePoint1() //准心的放大与缩小动画 { if (interact) { img.sprite = Spr2; } else { img.sprite = Spr1; } //准心不显示 } }