40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
[ExecuteInEditMode]
|
|
public class MakeRoll : MonoBehaviour
|
|
{
|
|
public GameObject prefab; // 需要生成的 prefab
|
|
public int numberOfObjects; // 输入的对象数量
|
|
public float angle; // 输入的角度
|
|
public float radius; // 输入的半径
|
|
public float XRotation;
|
|
|
|
void Start()
|
|
{
|
|
GenerateRing();
|
|
}
|
|
|
|
void GenerateRing()
|
|
{
|
|
float angleStep = angle / numberOfObjects; // 每个对象之间的角度
|
|
|
|
for (int i = 0; i < numberOfObjects; i++)
|
|
{
|
|
float currentAngle = i * angleStep * Mathf.Deg2Rad; // 当前角度(弧度)
|
|
Vector3 position = new Vector3(Mathf.Cos(currentAngle), 0, Mathf.Sin(currentAngle)) * radius; // 计算位置
|
|
GameObject myGameObject = Instantiate(prefab, position, Quaternion.identity); // 实例化 prefab
|
|
myGameObject.transform.parent = transform;
|
|
|
|
myGameObject.transform.rotation = Quaternion.Euler(90, 0, currentAngle * Mathf.Rad2Deg + 90); // 添加 X 轴旋转
|
|
myGameObject.transform.Rotate(XRotation, 0, 0, Space.Self); // 修正旋转方式
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|