页面编辑wordpress,wordpress速度优化,四川省建设监理管理协会网站,网络营销的特点及优势我们知道在OnValidate中创建游戏物体会发出警告#xff0c;删除游戏物体会报错。 所以我们使用协程#xff0c;将开始动作的信号放在OnValidate中#xff0c;将动作的执行放在帧结尾。
参考代码如下#xff1a;
using System.Collections;
using UnityEngine;public clas…我们知道在OnValidate中创建游戏物体会发出警告删除游戏物体会报错。 所以我们使用协程将开始动作的信号放在OnValidate中将动作的执行放在帧结尾。
参考代码如下
using System.Collections;
using UnityEngine;public class VerticalList : MonoBehaviour
{
#if UNITY_EDITOR[SerializeField]private int _childrenAmount 0;void OnValidate(){_childrenAmount Mathf.Max(_childrenAmount, 0);StartCoroutine(KeepChildrenAmount());}IEnumerator KeepChildrenAmount(){yield return new WaitForEndOfFrame();for (int i transform.childCount - 1; i _childrenAmount; --i)DestroyImmediate(transform.GetChild(i).gameObject);while (transform.childCount _childrenAmount){GameObject obj new();obj.transform.parent transform;}}
#endif
}