spawning added
This commit is contained in:
@@ -23,6 +23,10 @@ public class CameraFollower : MonoBehaviour
|
||||
|
||||
|
||||
void updateFrame(){
|
||||
if(PlayerController.boosting){
|
||||
//Add boost here
|
||||
}
|
||||
|
||||
float newX = Mathf.Lerp(transform.position.x, Target.position.x + offset.x, Xsmoothness);
|
||||
float newY = Mathf.Lerp(transform.position.y, Target.position.y + offset.y, Ysmoothness);
|
||||
transform.position = new Vector3(newX, newY, transform.position.z);
|
||||
|
||||
@@ -5,8 +5,12 @@ using UnityEngine.UI;
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public Text txt_money;
|
||||
public float moneyMultiplier = 5;
|
||||
public Vector3 txtMoneyOffset = Vector2.one;
|
||||
|
||||
void Update(){
|
||||
txt_money.text = "$"+PlayerController.t.position.y.ToString();
|
||||
txt_money.text = "$"+(PlayerController.t.position.y*moneyMultiplier).ToString("n4");
|
||||
|
||||
txt_money.rectTransform.position = Camera.main.WorldToScreenPoint(PlayerController.t.position + txtMoneyOffset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,10 @@ using UnityEngine;
|
||||
|
||||
public class OptionsSpawner : MonoBehaviour
|
||||
{
|
||||
public static OptionsSpawner instance{get; private set;}
|
||||
void Awake(){
|
||||
instance= this;
|
||||
public static OptionsSpawner instance { get; private set; }
|
||||
void Awake()
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
public Transform optionGood;
|
||||
public Transform optionBad;
|
||||
@@ -15,41 +16,60 @@ public class OptionsSpawner : MonoBehaviour
|
||||
public float SpawnTimer = 5;
|
||||
|
||||
float t;
|
||||
void Update(){
|
||||
if(!PlayerController.Started){return;}
|
||||
if(t < SpawnTimer){
|
||||
void Update()
|
||||
{
|
||||
if (!PlayerController.Started) { return; }
|
||||
if (t < SpawnTimer)
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
}else{
|
||||
t=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
t = 0;
|
||||
|
||||
|
||||
float newGoodRate = Random.Range(1.05f, 1.25f);
|
||||
float newBadRate = Random.Range(0.75f, 0.95f);
|
||||
|
||||
float newGoodRate = 1.05f + GetRandomRateDiff();
|
||||
SpawnGood(newGoodRate);
|
||||
SpawnBad(newBadRate);
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
float newBadRate = 0.95f - GetRandomRateDiff();
|
||||
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));
|
||||
|
||||
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<TextMesh>().text = $"+{((rate - 1f) * 100).ToString("n0")}%";
|
||||
newGood.name += ","+rate;
|
||||
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));
|
||||
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;
|
||||
newBad.GetComponentInChildren<TextMesh>().text = $"-{((1f - rate) * 100).ToString("n0")}%";
|
||||
newBad.name += "," + rate;
|
||||
}
|
||||
|
||||
public void Reposition(){
|
||||
public void Reposition()
|
||||
{
|
||||
// optionGood.position = PlayerController.instance.transform.position + (SpawnDistance * 1.5f);
|
||||
// optionBad.position = PlayerController.instance.transform.position + (SpawnDistance);
|
||||
|
||||
|
||||
@@ -5,12 +5,17 @@ using UnityEngine;
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
public static PlayerController instance{get; private set;}
|
||||
public Sprite upwardSprite;
|
||||
public Sprite downwardSprite;
|
||||
public Sprite normalSprite;
|
||||
public static Transform t {get {return instance.transform; }}
|
||||
void Awake(){
|
||||
instance= this;
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
}
|
||||
public Vector3 eulerAngles;
|
||||
public float movingSpeed = 1;
|
||||
public float boostSpeed= 2;
|
||||
public float turnAngle = 15;
|
||||
public GameObject trailPrefab;
|
||||
public Transform currentTrail;
|
||||
@@ -18,6 +23,7 @@ public class PlayerController : MonoBehaviour
|
||||
public float senseRadius = 5;
|
||||
|
||||
public bool isUp { get { return transform.eulerAngles.z != 360-turnAngle;}}
|
||||
SpriteRenderer spriteRenderer;
|
||||
void Start()
|
||||
{
|
||||
CameraFollower.Target = transform;
|
||||
@@ -51,23 +57,26 @@ public class PlayerController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
}
|
||||
bool boosting =false;
|
||||
public static bool boosting =false;
|
||||
IEnumerator giveBoost(float perc){
|
||||
boosting=true;
|
||||
float newY = transform.position.y * perc;
|
||||
spriteRenderer.sprite = (perc > 1) ? upwardSprite : downwardSprite;
|
||||
if(perc > 1){
|
||||
while(transform.position.y < newY){
|
||||
transform.position += new Vector3(0,movingSpeed,0);
|
||||
transform.position += new Vector3(0,boostSpeed,0);
|
||||
|
||||
if(!isUp){SwitchSide();}
|
||||
yield return new WaitForFixedUpdate();
|
||||
}
|
||||
}else{
|
||||
while(transform.position.y > newY){
|
||||
transform.position -= new Vector3(0,movingSpeed,0);
|
||||
transform.position -= new Vector3(0,boostSpeed,0);
|
||||
if(isUp){SwitchSide();}
|
||||
yield return new WaitForFixedUpdate();
|
||||
}
|
||||
}
|
||||
spriteRenderer.sprite = normalSprite;
|
||||
boosting=false;
|
||||
}
|
||||
|
||||
@@ -80,6 +89,9 @@ public class PlayerController : MonoBehaviour
|
||||
currentTrail = newTrail.transform;
|
||||
newTrail.GetComponent<TrailRenderer>().startColor = newTrail.GetComponent<TrailRenderer>().endColor = (isUp) ? Color.green:Color.red;
|
||||
|
||||
|
||||
// GetComponent<SpriteRenderer>().sprite = (isUp) ? upwardSprite : downwardSprite;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user