fixed
This commit is contained in:
@@ -4,6 +4,7 @@ using UnityEngine;
|
||||
|
||||
public class LevelGenerator : MonoBehaviour
|
||||
{
|
||||
public static LevelGenerator instance{get; private set;}
|
||||
[SerializeField]private GameObject LevelPrefab;
|
||||
[SerializeField]private GameObject TopPrefab;
|
||||
private List<GameObject> spawnedLevels = new List<GameObject>();
|
||||
@@ -13,17 +14,22 @@ public class LevelGenerator : MonoBehaviour
|
||||
[SerializeField]private float maxHigh;
|
||||
|
||||
[SerializeField]private List<float> Levels;
|
||||
|
||||
void Awake(){
|
||||
instance = this;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
GenerateAhead(150);
|
||||
}
|
||||
|
||||
|
||||
public void GenerateAhead(int count = 10){
|
||||
if(Levels.Count <= 0){
|
||||
Levels = new List<float>();
|
||||
}
|
||||
Levels.Add(1);
|
||||
|
||||
}
|
||||
int startIndex= Levels.Count;
|
||||
int lastIndex = Levels.Count +count;
|
||||
for(int i =startIndex; i < lastIndex; i++){
|
||||
|
||||
@@ -43,19 +43,15 @@ public class Player : MonoBehaviour
|
||||
Velocity = new Vector2(forwardSpeed,0);
|
||||
|
||||
CameraFollower.Target= body;
|
||||
CameraFollower.UpdateFrame();
|
||||
|
||||
playerRigidbody.bodyType = RigidbodyType2D.Static;
|
||||
playerRigidbody.gravityScale = 0;
|
||||
}
|
||||
|
||||
int lastX = 0;
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (!gameStarted && Input.GetKey(KeyCode.Space))
|
||||
{
|
||||
gameStarted = true;
|
||||
playerRigidbody.bodyType = RigidbodyType2D.Dynamic;
|
||||
playerRigidbody.gravityScale = gravity;
|
||||
}
|
||||
|
||||
|
||||
if (!gameStarted)
|
||||
{
|
||||
@@ -70,6 +66,11 @@ public class Player : MonoBehaviour
|
||||
}
|
||||
HandleJump();
|
||||
|
||||
if(lastX != (int)body.position.x){
|
||||
lastX = (int)body.position.x;
|
||||
LevelGenerator.instance.GenerateAhead(2);
|
||||
}
|
||||
|
||||
//Gravity
|
||||
Velocity -= new Vector2(0, gravity);
|
||||
|
||||
@@ -99,6 +100,12 @@ public class Player : MonoBehaviour
|
||||
|
||||
|
||||
public void Jump(){
|
||||
if (!gameStarted)
|
||||
{
|
||||
gameStarted = true;
|
||||
playerRigidbody.bodyType = RigidbodyType2D.Dynamic;
|
||||
playerRigidbody.gravityScale = gravity;
|
||||
}
|
||||
if(!isReadyToJump){ return; }
|
||||
jumpTimer =0;
|
||||
Velocity = new Vector2(Velocity.x, jumpForce);
|
||||
|
||||
@@ -7,7 +7,6 @@ public class TimeAliveMoney : MonoBehaviour
|
||||
public TMP_Text moneyText;
|
||||
public TMP_Text totalMoneyText;
|
||||
public Player player;
|
||||
private bool isAlive = true;
|
||||
private float timeAlive = 0f;
|
||||
private float totalMoneyEarned = 0f;
|
||||
|
||||
@@ -19,7 +18,7 @@ public class TimeAliveMoney : MonoBehaviour
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (player.gameStarted && isAlive == true) {
|
||||
if (player.gameStarted && player.isAlive == true) {
|
||||
timeAlive += Time.deltaTime;
|
||||
float earnedMoney = timeAlive * moneyPerSecond;
|
||||
if (moneyText != null)
|
||||
@@ -29,7 +28,6 @@ public class TimeAliveMoney : MonoBehaviour
|
||||
|
||||
public void OnPlayerDeath()
|
||||
{
|
||||
isAlive = false;
|
||||
totalMoneyEarned += timeAlive * moneyPerSecond;
|
||||
SaveMoney();
|
||||
timeAlive = 0f;
|
||||
|
||||
Reference in New Issue
Block a user