-
-
Save GigaOrts/c680a102a59350887c2f305633099d9c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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