中餐厅摆台-点击下一步一次显示骨碟碗勺并显示文字 距离
需要的预制体需要的脚本还有一个下一步的button最后的成品是最后是代码using UnityEngine;public class Billboard : MonoBehaviour{void LateUpdate(){transform.LookAt(transform.position Camera.main.transform.forward);}}using UnityEngine;[System.Serializable]public class PlaceStep{// 当前步骤要生成的餐具预制体public GameObject itemPrefab;// 对应场景里的点位Transformpublic Transform pointTrans;// 餐具显示名称用于悬浮文字标注public string showName;// 和上一个物体的标准间距(cm)用来显示距离文字public float spaceCm;}using UnityEngine;using UnityEngine.UI;using TMPro;public class TableStepManager : MonoBehaviour{[Header(摆台步骤列表按顺序填骨碟→汤碗→味碟...)]public PlaceStep[] stepList;[Header(下一步按钮)]public Button btnNext;[Header(名称距离文字UI预制体世界空间画布)]public GameObject tipUIPrefab;// 当前进行到第几步private int currentStepIndex 0;void Start(){// 绑定按钮点击事件btnNext.onClick.AddListener(NextStep);}void NextStep(){// 所有步骤执行完毕直接返回if (currentStepIndex stepList.Length){Debug.Log(全部餐具摆放完成);return;}// 取出当前步骤配置PlaceStep curStep stepList[currentStepIndex];Transform point curStep.pointTrans;// 核心生成代码按点位坐标、旋转生成父物体为table6GameObject itemObj Instantiate(curStep.itemPrefab,point.position,point.rotation,transform);// 生成餐具名称悬浮文字GameObject nameTip Instantiate(tipUIPrefab, itemObj.transform.position Vector3.up * 0.15f, Quaternion.identity, transform);nameTip.GetComponentInChildrenTextMeshProUGUI().text curStep.showName;nameTip.AddComponentBillboard();// 如果不是第一步计算和上一个物体的中点显示间距文字if (currentStepIndex 0){Transform lastItem transform.GetChild(transform.childCount - 2);Vector3 midPos (itemObj.transform.position lastItem.position) / 2;GameObject spaceTip Instantiate(tipUIPrefab, midPos, Quaternion.identity, transform);spaceTip.GetComponentInChildrenTextMeshProUGUI().text curStep.spaceCm cm;spaceTip.AddComponentBillboard();}// 步骤1等待下一次点击下一步currentStepIndex;}}