init
This commit is contained in:
30
Assets/Scripts/CameraFollower.cs
Normal file
30
Assets/Scripts/CameraFollower.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraFollower : MonoBehaviour
|
||||
{
|
||||
public static CameraFollower instance;
|
||||
void Awake(){
|
||||
instance = this;
|
||||
}
|
||||
public float Xsmoothness =1f;
|
||||
public float Ysmoothness =1f;
|
||||
public static Transform Target;
|
||||
public Vector2 offset;
|
||||
void FixedUpdate()
|
||||
{
|
||||
UpdateFrame();
|
||||
}
|
||||
|
||||
public static void UpdateFrame(){
|
||||
instance.updateFrame();
|
||||
}
|
||||
|
||||
|
||||
void updateFrame(){
|
||||
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);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/CameraFollower.cs.meta
Normal file
11
Assets/Scripts/CameraFollower.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ddf32660b2d7e9a4da8e78090da4272b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
12
Assets/Scripts/GameManager.cs
Normal file
12
Assets/Scripts/GameManager.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public Text txt_money;
|
||||
|
||||
void Update(){
|
||||
txt_money.text = "$"+PlayerController.t.position.y.ToString();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GameManager.cs.meta
Normal file
11
Assets/Scripts/GameManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3433d988438ba9249906784aa2e185f1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
57
Assets/Scripts/OptionsSpawner.cs
Normal file
57
Assets/Scripts/OptionsSpawner.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/OptionsSpawner.cs.meta
Normal file
11
Assets/Scripts/OptionsSpawner.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 525775e07cebbe24099d60af837eaaaa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
89
Assets/Scripts/PlayerController.cs
Normal file
89
Assets/Scripts/PlayerController.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
public static PlayerController instance{get; private set;}
|
||||
public static Transform t {get {return instance.transform; }}
|
||||
void Awake(){
|
||||
instance= this;
|
||||
}
|
||||
public Vector3 eulerAngles;
|
||||
public float movingSpeed = 1;
|
||||
public float turnAngle = 15;
|
||||
public GameObject trailPrefab;
|
||||
public Transform currentTrail;
|
||||
|
||||
public float senseRadius = 5;
|
||||
|
||||
public bool isUp { get { return transform.eulerAngles.z != 360-turnAngle;}}
|
||||
void Start()
|
||||
{
|
||||
CameraFollower.Target = transform;
|
||||
|
||||
}
|
||||
public static bool Started;
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if(boosting){return;}
|
||||
if(Input.GetKeyDown(KeyCode.Space)){
|
||||
SwitchSide();
|
||||
}
|
||||
}
|
||||
void FixedUpdate()
|
||||
{
|
||||
if(!Started){return;}
|
||||
transform.Translate(transform.right * movingSpeed);
|
||||
eulerAngles = transform.eulerAngles;
|
||||
|
||||
currentTrail.transform.position = transform.position;
|
||||
|
||||
if(boosting){return;}
|
||||
Collider2D overlap = Physics2D.OverlapCircle(transform.position, senseRadius);
|
||||
if(overlap!=null){
|
||||
if(overlap.name.Contains("option")){
|
||||
Debug.Log(overlap.name + " : " + overlap.name.LastIndexOf(","));
|
||||
float rate= float.Parse(overlap.name.Substring(overlap.name.LastIndexOf(",")+1));
|
||||
StartCoroutine(giveBoost(rate));
|
||||
|
||||
Destroy(overlap.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
bool boosting =false;
|
||||
IEnumerator giveBoost(float perc){
|
||||
boosting=true;
|
||||
float newY = transform.position.y * perc;
|
||||
if(perc > 1){
|
||||
while(transform.position.y < newY){
|
||||
transform.position += new Vector3(0,movingSpeed,0);
|
||||
if(!isUp){SwitchSide();}
|
||||
yield return new WaitForFixedUpdate();
|
||||
}
|
||||
}else{
|
||||
while(transform.position.y > newY){
|
||||
transform.position -= new Vector3(0,movingSpeed,0);
|
||||
if(isUp){SwitchSide();}
|
||||
yield return new WaitForFixedUpdate();
|
||||
}
|
||||
}
|
||||
boosting=false;
|
||||
}
|
||||
|
||||
|
||||
void SwitchSide(){
|
||||
Started=true;
|
||||
transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, isUp ? -turnAngle : turnAngle);
|
||||
|
||||
GameObject newTrail = Instantiate(trailPrefab, transform.position, Quaternion.identity);
|
||||
currentTrail = newTrail.transform;
|
||||
newTrail.GetComponent<TrailRenderer>().startColor = newTrail.GetComponent<TrailRenderer>().endColor = (isUp) ? Color.green:Color.red;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void OnDrawGizmos(){
|
||||
Gizmos.DrawWireSphere(transform.position, senseRadius);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/PlayerController.cs.meta
Normal file
11
Assets/Scripts/PlayerController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63b57bf3e88333740821b0e134876b30
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user