我想实现:给一组坐标,轮流读取这些坐标,每次读到新坐标时物体就在此刻的坐标生成,同时上次生成的物体消失。
4条回答 默认 最新
|__WhoAmI__| 2022-12-16 11:01关注using UnityEngine; public class CoordinateSpawner : MonoBehaviour { public GameObject Prefab; public Vector3[] coordinates; private GameObject lastInstance; void Start() { // 循环遍历坐标数组 foreach (Vector3 coord in coordinates) { // 如果 lastInstance 不为空,则销毁它 if (lastInstance != null) { Destroy(lastInstance); } // 在 coord 处实例化 Prefab 的副本 lastInstance = Instantiate(Prefab, coord, Quaternion.identity); } } }望采纳
本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报解决 1无用