1.创建3DUI
3DUI 需要创建新画布 画布模式改为worldSpace,并且指定摄像机
那个摄像机将来会看这个UI就把谁挂进去,并且3D画布下面的UI按钮需要被电击的话就需要摄像机身上必须挂在Physics Raycaster组件
2.创建侦听脚本给NPC,实现鼠标划入和离开还有点击事件
using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; using UnityEngine.EventSystems; public class ModelInterFaceLine : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler { GameObject Inven3D; void Start() { Inven3D= GameObject.FindWithTag("INVEN3D_UI"); Inven3D.SetActive(false); this.gameObject.transform.GetChild(0).gameObject.SetActive(false); } public void OnPointerClick(PointerEventData eventData) { Debug.Log("点击了我"); if (Inven3D!=null) { Inven3D.SetActive(true); } } public void OnPointerEnter(PointerEventData eventData) { this.gameObject.transform.AddComponent<Outline>(); this.gameObject.transform.GetChild(0).gameObject.SetActive(true); } public void OnPointerExit(PointerEventData eventData) { Destroy(this.gameObject.GetComponent<Outline>()); this.gameObject.transform.GetChild(0).gameObject.SetActive(false); } }