using System.Collections; using System.Collections.Generic; using UnityEngine; public class OptionsSpawner : MonoBehaviour { public static OptionsSpawner instance { get; private set; } void Awake() { instance = this; } public Transform optionGood; public Transform optionBad; public Vector2 SpawnDistanceMin; public Vector2 SpawnDistanceMax; public float SpawnTimer = 5; float t; void Update() { if (!PlayerController.Started) { return; } if (t < SpawnTimer) { t += Time.deltaTime; } else { t = 0; float newGoodRate = 1.05f + GetRandomRateDiff(); SpawnGood(newGoodRate); for (int i = 0; i < 2; i++) { float newBadRate = 0.95f - GetRandomRateDiff(); SpawnBad(newBadRate); } } } float GetRandomRateDiff() { float newRandom = Random.Range(1f, 100f); return 1- Mathf.Sqrt(newRandom) / 10f; } void SpawnGood(float rate, Vector3? position = null) { if (position == null) { position = PlayerController.t.position + new Vector3(PlayerController.t.right.x * Random.Range(SpawnDistanceMin.x, SpawnDistanceMax.x), PlayerController.t.right.y * Random.Range(SpawnDistanceMin.y, SpawnDistanceMax.y)); } Transform newGood = Instantiate(optionGood, (Vector3)position, Quaternion.identity); newGood.GetComponentInChildren().text = $"+{((rate - 1f) * 100).ToString("n0")}%"; newGood.name += "," + rate; } void SpawnBad(float rate, Vector3? position = null) { if (position == null) { position = PlayerController.t.position + new Vector3(PlayerController.t.right.x * Random.Range(SpawnDistanceMin.x, SpawnDistanceMax.x), PlayerController.t.right.y * Random.Range(SpawnDistanceMin.y, SpawnDistanceMax.y)); } Transform newBad = Instantiate(optionBad, (Vector3)position, Quaternion.identity); newBad.GetComponentInChildren().text = $"-{((1f - rate) * 100).ToString("n0")}%"; newBad.name += "," + rate; } public void Reposition() { // optionGood.position = PlayerController.instance.transform.position + (SpawnDistance * 1.5f); // optionBad.position = PlayerController.instance.transform.position + (SpawnDistance); } }