changes made, it was working before now space click isnt detected
This commit is contained in:
@@ -27,8 +27,15 @@ public class Player : MonoBehaviour
|
||||
|
||||
private SpriteRenderer spriteRenderer;
|
||||
|
||||
private TimeAliveMoney timeAliveMoney;
|
||||
public bool gameStarted = false;
|
||||
|
||||
|
||||
[SerializeField]private Rigidbody2D playerRigidbody;
|
||||
|
||||
void Start(){
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
timeAliveMoney = GetComponent<TimeAliveMoney>();
|
||||
isAlive = true;
|
||||
spriteRenderer.sprite =normalFace;
|
||||
|
||||
@@ -36,10 +43,25 @@ public class Player : MonoBehaviour
|
||||
Velocity = new Vector2(forwardSpeed,0);
|
||||
|
||||
CameraFollower.Target= body;
|
||||
|
||||
playerRigidbody.bodyType = RigidbodyType2D.Static;
|
||||
playerRigidbody.gravityScale = 0;
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (!gameStarted && Input.GetKey(KeyCode.Space))
|
||||
{
|
||||
gameStarted = true;
|
||||
playerRigidbody.bodyType = RigidbodyType2D.Dynamic;
|
||||
playerRigidbody.gravityScale = gravity;
|
||||
}
|
||||
|
||||
if (!gameStarted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(!isAlive){ return; }
|
||||
HandleDeath();
|
||||
|
||||
@@ -61,6 +83,7 @@ public class Player : MonoBehaviour
|
||||
if(col == null){ return;}
|
||||
if(col.tag == "Death"){
|
||||
Debug.Log("Im dead bro");
|
||||
timeAliveMoney.OnPlayerDeath();
|
||||
isAlive = false;
|
||||
spriteRenderer.sprite = sadFace;
|
||||
|
||||
|
||||
45
Assets/Scripts/TimeAliveMoney.cs
Normal file
45
Assets/Scripts/TimeAliveMoney.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
public class TimeAliveMoney : MonoBehaviour
|
||||
{
|
||||
public float moneyPerSecond = 0.1f;
|
||||
public TMP_Text moneyText;
|
||||
public TMP_Text totalMoneyText;
|
||||
public Player player;
|
||||
private bool isAlive = true;
|
||||
private float timeAlive = 0f;
|
||||
private float totalMoneyEarned = 0f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
totalMoneyEarned = PlayerPrefs.GetFloat("Money", 0f);
|
||||
totalMoneyText.text = ((int)totalMoneyEarned).ToString() + "$";
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (player.gameStarted && isAlive == true) {
|
||||
timeAlive += Time.deltaTime;
|
||||
float earnedMoney = timeAlive * moneyPerSecond;
|
||||
if (moneyText != null)
|
||||
moneyText.SetText(((int)earnedMoney).ToString() + "$");
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPlayerDeath()
|
||||
{
|
||||
isAlive = false;
|
||||
totalMoneyEarned += timeAlive * moneyPerSecond;
|
||||
SaveMoney();
|
||||
timeAlive = 0f;
|
||||
totalMoneyText.text = ((int)totalMoneyEarned).ToString() + "$";
|
||||
}
|
||||
|
||||
|
||||
private void SaveMoney()
|
||||
{
|
||||
PlayerPrefs.SetFloat("Money", totalMoneyEarned);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/TimeAliveMoney.cs.meta
Normal file
11
Assets/Scripts/TimeAliveMoney.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7dd3e53d990be444db17e0842da74b21
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user