Upgrade
This commit is contained in:
@@ -12,8 +12,9 @@ public class CameraFollower : MonoBehaviour
|
||||
public float Ysmoothness =1f;
|
||||
public static Transform Target;
|
||||
public Vector2 offset;
|
||||
void Update()
|
||||
void FixedUpdate()
|
||||
{
|
||||
UpdateFrame();
|
||||
}
|
||||
|
||||
public static void UpdateFrame(){
|
||||
|
||||
97
Assets/Scripts/DataManager.cs
Normal file
97
Assets/Scripts/DataManager.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public static class DataManager{
|
||||
public const string API_Endpoint="https://pogeracing.io/api/";
|
||||
public static string Username {
|
||||
get {if(PlayerPrefs.HasKey("username")){
|
||||
return PlayerPrefs.GetString("username");
|
||||
}else{
|
||||
return "";
|
||||
}
|
||||
}}
|
||||
private static string username;
|
||||
public static bool LoggedIn {get{return PlayerPrefs.HasKey("username");}}
|
||||
|
||||
public static int Money {
|
||||
get{
|
||||
if(PlayerPrefs.HasKey("money")){
|
||||
return PlayerPrefs.GetInt("money");
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
set{
|
||||
PlayerPrefs.SetInt("money",value);
|
||||
}
|
||||
}
|
||||
|
||||
public static int SpeedLevel {
|
||||
get{
|
||||
if(PlayerPrefs.HasKey("speed")){
|
||||
return PlayerPrefs.GetInt("speed");
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
set{
|
||||
PlayerPrefs.SetInt("speed",value);
|
||||
}
|
||||
}
|
||||
|
||||
public static int FuelLevel {
|
||||
get{
|
||||
if(PlayerPrefs.HasKey("fuel")){
|
||||
return PlayerPrefs.GetInt("fuel");
|
||||
PlayerPrefs.Save();
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
set{
|
||||
PlayerPrefs.SetInt("fuel",value);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
}
|
||||
|
||||
public static int inAirLevel {
|
||||
get{
|
||||
if(PlayerPrefs.HasKey("inAir")){
|
||||
return PlayerPrefs.GetInt("inAir");
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
set{
|
||||
PlayerPrefs.SetInt("inAir",value);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool OnLoginDone(string _username,string response){
|
||||
int uid = -1;
|
||||
try{
|
||||
uid = int.Parse(response);
|
||||
}catch{
|
||||
Debug.LogError("Error in registering : " + response);
|
||||
}
|
||||
|
||||
|
||||
if(uid >=0){
|
||||
username = _username +"#"+ uid;
|
||||
PlayerPrefs.SetString("username", username);
|
||||
PlayerPrefs.Save();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
11
Assets/Scripts/DataManager.cs.meta
Normal file
11
Assets/Scripts/DataManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6179ef5eb99010845b760cb4660ca4ec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
29
Assets/Scripts/Death.cs
Normal file
29
Assets/Scripts/Death.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Death : MonoBehaviour
|
||||
{
|
||||
public Vector3 headOffset;
|
||||
public float headRadius;
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
Collider2D[] overlaps = Physics2D.OverlapCircleAll(transform.position + headOffset, headRadius);
|
||||
foreach(Collider2D overlap in overlaps){
|
||||
if(overlap!=null){
|
||||
if(overlap.tag == "Ground"){
|
||||
Debug.Log("Die!");
|
||||
GameManager.GameOver();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OnDrawGizmos(){
|
||||
Gizmos.DrawWireSphere(transform.position+ headOffset, headRadius);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Death.cs.meta
Normal file
11
Assets/Scripts/Death.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11446a6ded11f2446a849e739cbf8b98
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -7,12 +7,30 @@ public class FuelManager : MonoBehaviour
|
||||
[Range(0f,100f)]
|
||||
public float FuelLevel;
|
||||
|
||||
public float[] FuelConsumptionLevels;
|
||||
public float FuelConsumption = 1;
|
||||
public static FuelManager instance {get; private set;}
|
||||
|
||||
public RectTransform fuelNeedle;
|
||||
public float fuelNeedleMax = 66;
|
||||
|
||||
void Awake(){
|
||||
instance= this;
|
||||
FuelConsumption = FuelConsumptionLevels[DataManager.FuelLevel];
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(FuelLevel >0){
|
||||
FuelLevel-=Time.deltaTime;
|
||||
FuelLevel-=Time.deltaTime * FuelConsumption;
|
||||
}else{
|
||||
GameManager.GameOver();
|
||||
}
|
||||
|
||||
fuelNeedle.eulerAngles = new Vector3(0,0, fuelNeedleMax - ((FuelLevel / 100f) * (fuelNeedleMax *2)));
|
||||
}
|
||||
|
||||
public void Refill(){
|
||||
FuelLevel = 100;
|
||||
}
|
||||
}
|
||||
|
||||
64
Assets/Scripts/FuelPickup.cs
Normal file
64
Assets/Scripts/FuelPickup.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FuelPickup : MonoBehaviour
|
||||
{
|
||||
public float sensorRadius = 2;
|
||||
public float shrinkSpeed = 0.1f;
|
||||
private Vector3 defaultSize;
|
||||
private SpriteRenderer spriteRenderer;
|
||||
void Start()
|
||||
{
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
defaultSize =transform.localScale;
|
||||
|
||||
Reposition();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if(!isActive){return;}
|
||||
Collider2D[] overlaps = Physics2D.OverlapCircleAll(transform.position, sensorRadius);
|
||||
foreach(Collider2D overlap in overlaps){
|
||||
if(overlap!=null){
|
||||
if(overlap.tag == "Player"){
|
||||
//Collect
|
||||
isActive=false;
|
||||
StartCoroutine(Collect());
|
||||
|
||||
FuelManager.instance.Refill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool isActive = true;
|
||||
IEnumerator Collect(){
|
||||
while(spriteRenderer.color.a > 0.2f){
|
||||
transform.localScale = Vector3.Lerp(transform.localScale, Vector3.zero, shrinkSpeed);
|
||||
spriteRenderer.color = new Color(spriteRenderer.color.r, spriteRenderer.color.g, spriteRenderer.color.b, Mathf.Lerp(spriteRenderer.color.a,0,shrinkSpeed));
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
|
||||
//Goto next position
|
||||
Reposition();
|
||||
isActive=true;
|
||||
}
|
||||
|
||||
|
||||
public void Reposition(){
|
||||
transform.localScale = defaultSize;
|
||||
spriteRenderer.color = new Color(spriteRenderer.color.r, spriteRenderer.color.g, spriteRenderer.color.b, 1);
|
||||
int carIndex= (int)(carController.instance.transform.position.x / LevelGenerator.instance.xMultiplier);
|
||||
float gap = Mathf.Clamp((carController.instance.transform.position.x / 2500f) * 150, 15,100);
|
||||
Debug.Log(gap);
|
||||
transform.position = LevelGenerator.instance.points[carIndex + (int)gap] + new Vector3(0,2);
|
||||
}
|
||||
|
||||
void OnDrawGizmos(){
|
||||
Gizmos.DrawWireSphere(transform.position, sensorRadius);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/FuelPickup.cs.meta
Normal file
11
Assets/Scripts/FuelPickup.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74d52ae040ddaf845acb72cf4033d512
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
53
Assets/Scripts/GameManager.cs
Normal file
53
Assets/Scripts/GameManager.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public static GameManager instance{get; private set;}
|
||||
public Text distanceTxt;
|
||||
public GameObject gameOverPanel;
|
||||
public Text thisDistance;
|
||||
public Text bestDistance;
|
||||
public Text txtEarnings;
|
||||
|
||||
void Awake(){
|
||||
instance=this;
|
||||
}
|
||||
public static void GameOver(){
|
||||
instance.gameOverPanel.SetActive(true);
|
||||
carController.GameOver();
|
||||
|
||||
instance.thisDistance.text = distanceTravelled + " m";
|
||||
instance.bestDistance.text = (PlayerPrefs.HasKey("best")? PlayerPrefs.GetInt("best").ToString() : distanceTravelled.ToString() ) + " m";
|
||||
|
||||
int earnings = (int)(distanceTravelled/10f);
|
||||
// DataManager.Money+=earnings;
|
||||
|
||||
instance.txtEarnings.text = "$" +earnings;
|
||||
}
|
||||
|
||||
private static int m_distance;
|
||||
public static int distanceTravelled {get {
|
||||
if(carController.isAlive){
|
||||
m_distance = (int)(carController.instance.transform.position.x);
|
||||
}
|
||||
|
||||
return m_distance;
|
||||
}}
|
||||
void Update(){
|
||||
if(carController.instance.transform.position.x > 0){
|
||||
distanceTxt.text = distanceTravelled + " m";
|
||||
}
|
||||
}
|
||||
|
||||
public void Reload(){
|
||||
SceneManager.LoadScene("LevelGen");
|
||||
}
|
||||
|
||||
public void LoadMenu(){
|
||||
SceneManager.LoadScene("Menu");
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GameManager.cs.meta
Normal file
11
Assets/Scripts/GameManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13ebdb4566d92ff4ab1e54136ac0a2d8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
58
Assets/Scripts/Leaderboard.cs
Normal file
58
Assets/Scripts/Leaderboard.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Leaderboard : MonoBehaviour
|
||||
{
|
||||
public GameObject rowPrefab;
|
||||
public Transform itemsParent;
|
||||
|
||||
public void Show(){
|
||||
gameObject.SetActive(true);
|
||||
|
||||
|
||||
StartCoroutine(show());
|
||||
}
|
||||
|
||||
|
||||
IEnumerator show(){
|
||||
WWW req = new WWW(DataManager.API_Endpoint +"get_leaderboard.php");
|
||||
yield return req;
|
||||
|
||||
Debug.Log("Leaderboard: " + req.text);
|
||||
|
||||
if(req.text.Contains("<td>") && req.text.Contains("<tr>")){
|
||||
|
||||
string[] col = {"<td>"};
|
||||
string[] row = {"<tr>"};
|
||||
|
||||
string[] columns = req.text.Split(col,System.StringSplitOptions.RemoveEmptyEntries);
|
||||
//Purge
|
||||
for(int i=0; i < itemsParent.childCount; i++){
|
||||
if(itemsParent.GetChild(i).gameObject != rowPrefab){
|
||||
Destroy(itemsParent.GetChild(i).gameObject);
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
rowPrefab.SetActive(true);
|
||||
for (int i =0; i < columns.Length; i++)
|
||||
{
|
||||
string column = columns[i];
|
||||
string[] rows = column.Split(row, System.StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if(rows.Length < 2){
|
||||
Debug.Log("Error");
|
||||
}
|
||||
|
||||
|
||||
GameObject newRow = Instantiate(rowPrefab, itemsParent);
|
||||
newRow.transform.GetChild(0).GetComponent<Text>().text = $"{i+1}. {rows[0]}";
|
||||
newRow.transform.GetChild(1).GetComponent<Text>().text =rows[1] + " m";
|
||||
}
|
||||
rowPrefab.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Leaderboard.cs.meta
Normal file
11
Assets/Scripts/Leaderboard.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e1b7dedd9a4c3a48beb8d9c72821cf1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -5,6 +5,7 @@ using UnityEngine.U2D;
|
||||
|
||||
public class LevelGenerator : MonoBehaviour
|
||||
{
|
||||
public static LevelGenerator instance { get; private set; }
|
||||
public GameObject spritePrefab;
|
||||
public int startPoints = 500;
|
||||
public int trendChangeThreshold = 10;
|
||||
@@ -15,8 +16,9 @@ public class LevelGenerator : MonoBehaviour
|
||||
bool goingUp = false;
|
||||
int lastIndex =0;
|
||||
SpriteShapeController curSpriteController;
|
||||
void Start()
|
||||
void Awake()
|
||||
{
|
||||
instance = this;
|
||||
points = new Vector3[startPoints];
|
||||
for(int i=0; i < startPoints; i++){
|
||||
if(i < 1){
|
||||
|
||||
41
Assets/Scripts/Login.cs
Normal file
41
Assets/Scripts/Login.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
public class Login : MonoBehaviour
|
||||
{
|
||||
public InputField loginInput;
|
||||
public Button loginBtn;
|
||||
|
||||
|
||||
void Awake(){
|
||||
if(DataManager.LoggedIn){
|
||||
SceneManager.LoadScene(1);
|
||||
}
|
||||
loginBtn.onClick.AddListener(OnLogin);
|
||||
loginInput.onValueChanged.AddListener(OnInputChanged);
|
||||
|
||||
loginBtn.interactable=false;
|
||||
}
|
||||
public void OnLogin(){
|
||||
StartCoroutine(login(loginInput.text));
|
||||
}
|
||||
|
||||
void OnInputChanged(string newVal){
|
||||
loginBtn.interactable = newVal.Length > 2;
|
||||
}
|
||||
|
||||
IEnumerator login(string username){
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("username", username);
|
||||
form.AddField("key","#2CuV1Bit^S!sW1ZcgRv8BhrO");
|
||||
|
||||
WWW req = new WWW(DataManager.API_Endpoint +"register_instant.php", form);
|
||||
yield return req;
|
||||
|
||||
if(DataManager.OnLoginDone(username, req.text)){
|
||||
SceneManager.LoadScene(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Login.cs.meta
Normal file
11
Assets/Scripts/Login.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4298e4b28e5f9e842a01e087801b1a17
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
46
Assets/Scripts/MenuManager.cs
Normal file
46
Assets/Scripts/MenuManager.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
public class MenuManager : MonoBehaviour
|
||||
{
|
||||
public Text txtUsername;
|
||||
public Text txtBest;
|
||||
public Text txtMoney;
|
||||
|
||||
public Button playBtn;
|
||||
public Button leaderboardBtn;
|
||||
public Leaderboard leaderboard;
|
||||
public static MenuManager instance;
|
||||
void Start()
|
||||
{
|
||||
instance = this;
|
||||
if(!DataManager.LoggedIn){SceneManager.LoadScene(0); return;}
|
||||
Refresh();
|
||||
|
||||
playBtn.onClick.AddListener(OnPlay);
|
||||
leaderboardBtn.onClick.AddListener(OnLeaderboardBtn);
|
||||
}
|
||||
|
||||
void OnPlay(){
|
||||
SceneManager.LoadScene(2);
|
||||
}
|
||||
|
||||
void OnLeaderboardBtn(){
|
||||
leaderboard.Show();
|
||||
}
|
||||
|
||||
public static void Refresh(){
|
||||
if(instance != null){
|
||||
instance.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
|
||||
txtUsername.text = txtUsername.text.Replace("{username}", DataManager.Username);
|
||||
txtBest.text = "Personal Best : " + (PlayerPrefs.HasKey("best") ? PlayerPrefs.GetInt("best") : 0) + " m";
|
||||
txtMoney.text = "$"+ DataManager.Money;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/MenuManager.cs.meta
Normal file
11
Assets/Scripts/MenuManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 474b1819f34c1224192a1651fccc4bb7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
146
Assets/Scripts/UpgradeMenu.cs
Normal file
146
Assets/Scripts/UpgradeMenu.cs
Normal file
@@ -0,0 +1,146 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UpgradeMenu : MonoBehaviour
|
||||
{
|
||||
public Transform speedBar;
|
||||
public Transform fuelBar;
|
||||
public Transform inAirBar;
|
||||
public Button btnUpgradeSpeed,btnUpgradeFuel,btnUpgradeInAir;
|
||||
|
||||
|
||||
|
||||
void Start(){
|
||||
Refresh();
|
||||
|
||||
|
||||
btnUpgradeSpeed.onClick.AddListener(UpgradeSpeed);
|
||||
btnUpgradeFuel.onClick.AddListener(UpgradeFuel);
|
||||
btnUpgradeInAir.onClick.AddListener(UpgradeInAir);
|
||||
}
|
||||
|
||||
public void Show(){
|
||||
gameObject.SetActive(true);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void UpgradeSpeed(){
|
||||
DataManager.SpeedLevel++;
|
||||
DataManager.Money -= speedPrice;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void UpgradeFuel(){
|
||||
DataManager.FuelLevel++;
|
||||
DataManager.Money-= fuelPrice;
|
||||
Refresh();
|
||||
} void UpgradeInAir(){
|
||||
DataManager.inAirLevel++;
|
||||
DataManager.Money-=inAirPrice;
|
||||
Refresh();
|
||||
}
|
||||
int speedPrice;
|
||||
int fuelPrice ;
|
||||
int inAirPrice ;
|
||||
|
||||
int priceIncrementRate = 100;
|
||||
void Refresh(){
|
||||
int speedLevel = DataManager.SpeedLevel;
|
||||
int fuelLevel = DataManager.FuelLevel;
|
||||
int inAirLevel = DataManager.inAirLevel;
|
||||
|
||||
speedPrice = 0;
|
||||
fuelPrice = 0;
|
||||
inAirPrice = 0;
|
||||
|
||||
bool speedAvailable = true;
|
||||
bool fuelAvailable = true;
|
||||
bool inAirAvailable = true;
|
||||
for(int i=0; i<speedBar.childCount; i++){
|
||||
if(speedBar.GetChild(i).GetComponent<Image>()!=null){
|
||||
|
||||
if( i <= speedLevel ){
|
||||
speedBar.GetChild(i).GetComponent<Image>().color = Color.green;
|
||||
speedPrice += priceIncrementRate;
|
||||
}else{
|
||||
speedBar.GetChild(i).GetComponent<Image>().color = Color.gray;
|
||||
}
|
||||
}
|
||||
|
||||
if(i == speedBar.childCount-1){
|
||||
if(i == speedLevel){
|
||||
speedAvailable =false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0; i<fuelBar.childCount; i++){
|
||||
if(fuelBar.GetChild(i).GetComponent<Image>()!=null){
|
||||
|
||||
if( i <= fuelLevel ){
|
||||
fuelBar.GetChild(i).GetComponent<Image>().color = Color.green;
|
||||
fuelPrice += priceIncrementRate;
|
||||
}else{
|
||||
fuelBar.GetChild(i).GetComponent<Image>().color = Color.gray;
|
||||
}
|
||||
}
|
||||
|
||||
if(i == fuelBar.childCount-1){
|
||||
if(i == fuelLevel){
|
||||
fuelAvailable =false;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int i=0; i<inAirBar.childCount; i++){
|
||||
if(inAirBar.GetChild(i).GetComponent<Image>()!=null){
|
||||
|
||||
if( i <= inAirLevel ){
|
||||
inAirBar.GetChild(i).GetComponent<Image>().color = Color.green;
|
||||
inAirPrice += priceIncrementRate;
|
||||
}else{
|
||||
inAirBar.GetChild(i).GetComponent<Image>().color = Color.gray;
|
||||
}
|
||||
}
|
||||
|
||||
if(i == inAirBar.childCount-1){
|
||||
if(i == inAirLevel){
|
||||
inAirAvailable =false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
btnUpgradeSpeed.image.color = speedAvailable ? Color.green : Color.gray;
|
||||
btnUpgradeFuel.image.color = fuelAvailable ? Color.green : Color.gray;
|
||||
btnUpgradeInAir.image.color = inAirAvailable ? Color.green : Color.gray;
|
||||
|
||||
if(speedPrice > DataManager.Money){
|
||||
speedAvailable=false;
|
||||
btnUpgradeSpeed.image.color = Color.red;
|
||||
}
|
||||
|
||||
if(fuelPrice > DataManager.Money){
|
||||
fuelAvailable=false;
|
||||
btnUpgradeFuel.image.color = Color.red;
|
||||
}
|
||||
|
||||
if(inAirPrice > DataManager.Money){
|
||||
inAirAvailable=false;
|
||||
btnUpgradeInAir.image.color = Color.red;
|
||||
}
|
||||
|
||||
|
||||
btnUpgradeSpeed.interactable = speedAvailable;
|
||||
btnUpgradeFuel.interactable = fuelAvailable;
|
||||
btnUpgradeInAir.interactable = inAirAvailable;
|
||||
|
||||
|
||||
btnUpgradeSpeed.transform.GetChild(1).GetComponent<Text>().text = $"${speedPrice}";
|
||||
btnUpgradeFuel.transform.GetChild(1).GetComponent<Text>().text = $"${fuelPrice}";
|
||||
btnUpgradeInAir.transform.GetChild(1).GetComponent<Text>().text = $"${inAirPrice}";
|
||||
|
||||
MenuManager.Refresh();
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/UpgradeMenu.cs.meta
Normal file
11
Assets/Scripts/UpgradeMenu.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 47ba73fd7ff3ab644932970204215458
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -10,7 +10,9 @@ public class carController : MonoBehaviour
|
||||
|
||||
JointMotor2D motorFront;
|
||||
JointMotor2D motorBack;
|
||||
|
||||
public float[] SpeedF,SpeedB;
|
||||
public float[] Torque;
|
||||
public float[] RotationSpeed;
|
||||
public float speedF;
|
||||
public float speedB;
|
||||
|
||||
@@ -22,15 +24,74 @@ public class carController : MonoBehaviour
|
||||
|
||||
public float carRotationSpeed;
|
||||
|
||||
void Start()
|
||||
public static bool isAlive = true;
|
||||
public static void GameOver(){
|
||||
if(!isAlive){return;}
|
||||
|
||||
isAlive=false;
|
||||
instance.gameOverPanel.SetActive(true);
|
||||
|
||||
|
||||
if(PlayerPrefs.HasKey("best")){
|
||||
if(PlayerPrefs.GetInt("best") < GameManager.distanceTravelled){
|
||||
PlayerPrefs.SetInt("best", GameManager.distanceTravelled);
|
||||
|
||||
}
|
||||
}else{
|
||||
PlayerPrefs.SetInt("best", GameManager.distanceTravelled);
|
||||
}
|
||||
instance.setBest(GameManager.distanceTravelled);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void setBest(int best){
|
||||
if(SentBestReq){return;}
|
||||
SentBestReq=true;
|
||||
int earnings = (int)(GameManager.distanceTravelled/10f);
|
||||
DataManager.Money+=earnings;
|
||||
StartCoroutine(SetBest(best));
|
||||
}
|
||||
bool SentBestReq=false;
|
||||
|
||||
IEnumerator SetBest(int best){
|
||||
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("username", DataManager.Username);
|
||||
form.AddField("best", best);
|
||||
|
||||
WWW req = new WWW(DataManager.API_Endpoint + "set_best.php", form);
|
||||
yield return req;
|
||||
|
||||
Debug.Log(req.text);
|
||||
}
|
||||
|
||||
|
||||
public GameObject gameOverPanel;
|
||||
public static carController instance{get; private set;}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
instance = this;
|
||||
isAlive=true;
|
||||
CameraFollower.Target = transform;
|
||||
|
||||
speedF = SpeedF[DataManager.SpeedLevel];
|
||||
speedB = SpeedB[DataManager.SpeedLevel];
|
||||
torqueF = torqueB = Torque[DataManager.SpeedLevel];
|
||||
|
||||
carRotationSpeed = RotationSpeed[DataManager.inAirLevel];
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (Input.GetAxisRaw("Vertical") > 0)
|
||||
if(!isAlive){
|
||||
rearWheel.useMotor = false;
|
||||
frontWheel.useMotor = false;
|
||||
return;
|
||||
}
|
||||
if (Input.GetAxisRaw("Horizontal") > 0)
|
||||
{
|
||||
if (TractionFront)
|
||||
{
|
||||
@@ -45,7 +106,7 @@ public class carController : MonoBehaviour
|
||||
rearWheel.motor = motorBack;
|
||||
}
|
||||
}
|
||||
else if (Input.GetAxisRaw("Vertical") < 0)
|
||||
else if (Input.GetAxisRaw("Horizontal") < 0)
|
||||
{
|
||||
if (TractionFront)
|
||||
{
|
||||
@@ -66,12 +127,12 @@ public class carController : MonoBehaviour
|
||||
frontWheel.useMotor = false;
|
||||
}
|
||||
|
||||
if (Input.GetAxisRaw("Vertical") != 0)
|
||||
if (Input.GetAxisRaw("Horizontal") != 0)
|
||||
{
|
||||
GetComponent<Rigidbody2D>().AddTorque(carRotationSpeed * Input.GetAxisRaw("Vertical") * 1);
|
||||
GetComponent<Rigidbody2D>().AddTorque(carRotationSpeed * Input.GetAxisRaw("Horizontal") * 1);
|
||||
}
|
||||
|
||||
|
||||
CameraFollower.UpdateFrame();
|
||||
// CameraFollower.UpdateFrame();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user