using UnityEngine; public class test2 : MonoBehaviour { public float RandomPos; public GameObject MonsterPrefab; private void onm ouseDown() { float posx = transform.position.x + Random.Range(-RandomPos + 3, RandomPos - 3);//获取随机X轴坐标 float posz = transform.position.z + Random.Range(-RandomPos + 3, RandomPos - 3);//获取随机Z轴坐标 Vector3 randomNewPos = new Vector3(posx, transform.position.y, posz);//组合成新的三维坐标 Instantiate(MonsterPrefab, randomNewPos, Quaternion.identity);//生成怪物 } void OnDrawGizmosSelected() { //设置范围颜色 Gizmos.color = Color.white; //画出刷怪范围 Gizmos.DrawWireSphere(transform.position, RandomPos); } }标签:RandomPos,float,transform,unity,怪物,position,public,随机 From: https://www.cnblogs.com/alanshreck/p/16945457.html