using UnityEngine;

public class NewBehaviourScript : MonoBehaviour {
	public GameObject prefab;
	void Update()
	{
		//位置
		float x = Random.Range(-10, 10);
		float y = Random.Range(-10, 10);
		float z = Random.Range(-10, 10);
		Vector3 pos = new Vector3(x,y,z);
		//实例化
		Instantiate(prefab,pos,Quaternion.identity);

	}
}

效果:
脚本绑定到到物件,把任意prefab拖到脚本中的Prefab的参数上,运行,每一帧都在空间内随机生成一个prefab的实例

相关文章:

  • 2022-12-23
  • 2021-09-10
  • 2021-09-13
  • 2021-05-10
  • 2021-12-31
  • 2021-04-28
  • 2021-07-03
猜你喜欢
  • 2021-11-28
  • 2022-12-23
  • 2021-05-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案