You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
3 weeks ago
|
using UnityEngine;
|
||
|
|
||
|
public class PlatformSpawner : MonoBehaviour
|
||
|
{
|
||
|
[Header("Platform Settings")]
|
||
|
public GameObject platformPrefab; // Prefab of the platform to instantiate
|
||
|
public int numberOfPlayers = 2; // Number of players (n)
|
||
|
public float planeRadius = 10f; // Radius of the circular plane
|
||
|
|
||
|
private void Start()
|
||
|
{
|
||
|
if (platformPrefab == null)
|
||
|
{
|
||
|
Debug.LogError("Platform Prefab is not assigned!");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
SpawnPlatforms();
|
||
|
}
|
||
|
|
||
|
private void SpawnPlatforms()
|
||
|
{
|
||
|
int platformsToSpawn = numberOfPlayers - 1;
|
||
|
|
||
|
if (platformsToSpawn <= 0)
|
||
|
{
|
||
|
Debug.LogWarning("Not enough players to spawn platforms.");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
float angleIncrement = 360f / platformsToSpawn; // Divide the circle into equal segments
|
||
|
|
||
|
for (int i = 0; i < platformsToSpawn; i++)
|
||
|
{
|
||
|
// Calculate angle in radians
|
||
|
float angle = i * angleIncrement * Mathf.Deg2Rad;
|
||
|
|
||
|
// Determine the position on the circular plane
|
||
|
Vector3 position = new Vector3(
|
||
|
Mathf.Cos(angle) * planeRadius,
|
||
|
0f, // Assume the circular plane is on the XZ plane
|
||
|
Mathf.Sin(angle) * planeRadius
|
||
|
);
|
||
|
|
||
|
// Instantiate the platform
|
||
|
Instantiate(platformPrefab, position, Quaternion.identity);
|
||
|
}
|
||
|
|
||
|
Debug.Log($"Spawned {platformsToSpawn} platforms on a circular plane.");
|
||
|
}
|
||
|
}
|