1.核心代码示例
2.代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class AddRandomChilden : MonoBehaviour
{// Debug.Log("开始进入update");float i = 0;// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){if (i >1){Debug.Log("开始创建sphere");;int xRange=Random.Range(-10,10);int zRange=Random.Range(-10,10);GameObject objB = Instantiate(GameObject.CreatePrimitive(PrimitiveType.Sphere), transform);objB.transform.position = new Vector3(xRange, 0,zRange);objB.transform.localScale = new Vector3(0.3f, 0.3f,0.3f);i = 0;}i += Time.deltaTime ;Debug.Log(i);}
}