| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- using System.Collections;
- using UnityEngine;
- using UnityEngine.UIElements;
- public class OrbManager : MonoBehaviour
- {
- public GameObject prefab;
- public int orbsToSpawn;
- private int orbsSpawned;
- public int spawnRadius;
- private GameObject player;
- public IEnumerator StartSpawn()
- {
- player = GameObject.Find("Player");
- orbsSpawned = 0;
- yield return new WaitForSeconds(5);
- while (orbsSpawned < orbsToSpawn)
- {
- TrySpawnOrb();
- }
- }
- void TrySpawnOrb()
- {
- float xRadius = UnityEngine.Random.Range(-spawnRadius, spawnRadius);
- float zRadius = UnityEngine.Random.Range(-spawnRadius, spawnRadius);
- Vector3 randomRadiusVector = new Vector3(xRadius, 0, zRadius);
- Vector3 rayStart = player.transform.position + Vector3.up * 300 + randomRadiusVector;
- if (Physics.Raycast(rayStart, Vector3.down, out RaycastHit hit, 600f))
- {
- if (hit.point.y < OrbData.maxHeight && hit.point.y > OrbData.minHeight)
- {
- UnityEngine.Object.Instantiate(prefab, hit.point + new Vector3(0f, 0.75f, 0f), Quaternion.identity);
- orbsSpawned++;
- }
- }
- }
- }
|