31 lines
1013 B
C#
31 lines
1013 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
[ExecuteInEditMode]
|
|
public class RollCollenter : MonoBehaviour
|
|
{
|
|
public float angle; // 输入的角度
|
|
public float radius; // 输入的半径
|
|
public float XRotation;
|
|
|
|
void Start()
|
|
{
|
|
GenerateRing();
|
|
}
|
|
|
|
void GenerateRing()
|
|
{
|
|
float angleStep = angle / transform.childCount; // 每个对象之间的角度
|
|
|
|
for (int i = 0; i < transform.childCount; i++)
|
|
{
|
|
float currentAngle = i * angleStep * Mathf.Deg2Rad; // 当前角度(弧度)
|
|
Vector3 position = new Vector3(Mathf.Cos(currentAngle), 0, Mathf.Sin(currentAngle)) * radius; // 计算位置
|
|
transform.GetChild(i).position=position;
|
|
transform.GetChild(i).rotation = Quaternion.Euler(90, 0, currentAngle * Mathf.Rad2Deg + 90); // 添加 X 轴旋转
|
|
transform.GetChild(i).transform.Rotate(XRotation, 0, 0, Space.Self); // 修正旋转方式
|
|
|
|
}
|
|
}
|
|
}
|