using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test_sphere : MonoBehaviour{
private Vector3 centerPos; //你围绕那个点 就用谁的角度
private float radius = 3; //物理离 centerPos的距离
private float angle = 0; //偏移角度
void Start()
{
CreateSphere();
}
public void CreateSphere()
{
centerPos = transform.position;
//20度生成一个圆
for (int i=0; i<1000 ;i++)
{
Vector3 p = Random.insideUnitSphere * radius;
Vector3 pos = p.normalized * (2 + p.magnitude);
GameObject obj1 = GameObject.CreatePrimitive(PrimitiveType.Sphere);
//设置物体的位置Vector3三个参数分别代表x,y,z的坐标数
obj1.transform.position = pos;
}
}
}
运行代码,发现 围绕该 物体 的坐标,生成一个空心球体。
Random.insideUnitSphere
Returns a random point inside a sphere with radius 1 (Read Only).

这篇博客介绍了如何使用Unity的Random.insideUnitSphere方法,在一个单位半径的球体内生成随机坐标,从而实现物体在空心球体内部环绕一点的分布。内容提及参考了关于Unity生成圆圈和空心圆范围内随机生成物体的文章。
最低0.47元/天 解锁文章
6565

被折叠的 条评论
为什么被折叠?



