Skip to content

Instantly share code, notes, and snippets.

@GigaOrts
Created July 30, 2025 20:09
Show Gist options
  • Save GigaOrts/c680a102a59350887c2f305633099d9c to your computer and use it in GitHub Desktop.
Save GigaOrts/c680a102a59350887c2f305633099d9c to your computer and use it in GitHub Desktop.
using UnityEngine;
public class AsteroidSpawner : MonoBehaviour
{
[SerializeField] private GameObject asteroidPresentationPrefab;
[SerializeField] private float innerRadius = 5f; // Внутренний радиус (зона, где нельзя спавниться)
[SerializeField] private float outerRadius = 10f; // Внешний радиус
public void Create(int asteroidCount)
{
for (int i = 0; i < asteroidCount; i++)
{
Vector2 position;
do
{
position = Random.insideUnitCircle * outerRadius; // Генерируем случайную позицию
}
while (position.magnitude < innerRadius); // Проверяем, что позиция не находится внутри "дырки"
var rotation = Quaternion.identity;
Instantiate(asteroidPresentationPrefab, position, rotation);
}
}
}
Vector3 RandomPointInRing3D(Vector3 center, float minRadius, float maxRadius)
{
float angle = Random.Range(0f, Mathf.PI * 2f);
float radius = Random.Range(minRadius, maxRadius);
float x = center.x + Mathf.Cos(angle) * radius;
float y = center.y + Mathf.Sin(angle) * radius;
return new Vector3(x, y, center.z); // или нужная координата z
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment