58 lines
2.1 KiB
C#
58 lines
2.1 KiB
C#
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 = Random.Range(1.05f, 1.25f);
|
|
float newBadRate = Random.Range(0.75f, 0.95f);
|
|
|
|
SpawnGood(newGoodRate);
|
|
SpawnBad(newBadRate);
|
|
}
|
|
}
|
|
|
|
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<TextMesh>().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<TextMesh>().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);
|
|
|
|
}
|
|
}
|