Optimize arrow finding code & add commas to scores
This commit is contained in:
@@ -8,7 +8,8 @@ public class ButtonToScene : MonoBehaviour
|
||||
|
||||
void Awake()
|
||||
{
|
||||
gameObject.GetComponent<Button>().onClick.AddListener(async () => {
|
||||
gameObject.GetComponent<Button>().onClick.AddListener(async () =>
|
||||
{
|
||||
await SceneManager.LoadSceneAsync(sceneName);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -25,6 +25,11 @@ public class GamePlayer : MonoBehaviour
|
||||
private float nextUpdate;
|
||||
private float fps;
|
||||
public SpriteRenderer overlayRender;
|
||||
public GameObject leftArrow;
|
||||
public GameObject rightArrow;
|
||||
public GameObject jumpArrow;
|
||||
public GameObject restartButton;
|
||||
public GameObject backButton;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
@@ -81,14 +86,14 @@ public class GamePlayer : MonoBehaviour
|
||||
PlayerPrefs.Save();
|
||||
backgroundMusic.volume = PlayerPrefs.GetFloat("musicVolume", 1f);
|
||||
screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||
highScoreText.text = $"High Score: {highscore}";
|
||||
highScoreText.text = $"High Score: {Tools.FormatWithCommas(highscore)}";
|
||||
if (Application.isMobilePlatform)
|
||||
{
|
||||
GameObject leftArrow = new("LeftArrow");
|
||||
GameObject rightArrow = new("RightArrow");
|
||||
GameObject jumpArrow = new("JumpArrow");
|
||||
GameObject restartButton = new("RestartButton");
|
||||
GameObject backButton = new("BackButton");
|
||||
leftArrow = new("LeftArrow");
|
||||
rightArrow = new("RightArrow");
|
||||
jumpArrow = new("JumpArrow");
|
||||
restartButton = new("RestartButton");
|
||||
backButton = new("BackButton");
|
||||
leftArrow.AddComponent<SpriteRenderer>();
|
||||
rightArrow.AddComponent<SpriteRenderer>();
|
||||
jumpArrow.AddComponent<SpriteRenderer>();
|
||||
@@ -96,10 +101,15 @@ public class GamePlayer : MonoBehaviour
|
||||
backButton.AddComponent<SpriteRenderer>();
|
||||
|
||||
leftArrow.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("Arrows/Arrow");
|
||||
leftArrow.GetComponent<SpriteRenderer>().sortingOrder = 1000;
|
||||
rightArrow.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("Arrows/Arrow");
|
||||
rightArrow.GetComponent<SpriteRenderer>().sortingOrder = 1000;
|
||||
jumpArrow.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("Arrows/Arrow");
|
||||
jumpArrow.GetComponent<SpriteRenderer>().sortingOrder = 1000;
|
||||
restartButton.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("Arrows/Restart");
|
||||
restartButton.GetComponent<SpriteRenderer>().sortingOrder = 1000;
|
||||
backButton.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("Arrows/Back");
|
||||
backButton.GetComponent<SpriteRenderer>().sortingOrder = 1000;
|
||||
|
||||
leftArrow.transform.rotation = UnityEngine.Quaternion.Euler(0f, 0f, 90f);
|
||||
rightArrow.transform.rotation = UnityEngine.Quaternion.Euler(0f, 0f, -90f);
|
||||
@@ -161,11 +171,6 @@ public class GamePlayer : MonoBehaviour
|
||||
}
|
||||
if (Application.isMobilePlatform)
|
||||
{
|
||||
GameObject leftArrow = GameObject.Find("LeftArrow");
|
||||
GameObject rightArrow = GameObject.Find("RightArrow");
|
||||
GameObject jumpArrow = GameObject.Find("JumpArrow");
|
||||
GameObject restartButton = GameObject.Find("RestartButton");
|
||||
GameObject backButton = GameObject.Find("BackButton");
|
||||
if (!Application.isMobilePlatform)
|
||||
{
|
||||
if (Mouse.current.leftButton.isPressed)
|
||||
@@ -197,7 +202,8 @@ public class GamePlayer : MonoBehaviour
|
||||
else
|
||||
{
|
||||
var touches = UnityEngine.InputSystem.EnhancedTouch.Touch.activeTouches;
|
||||
for (int i = 0; i < touches.Count; i++) {
|
||||
for (int i = 0; i < touches.Count; i++)
|
||||
{
|
||||
var pos = touches[i].screenPosition;
|
||||
UnityEngine.Vector3 clickPosition = Camera.main.ScreenToWorldPoint(new UnityEngine.Vector3(pos.x, pos.y, 0f));
|
||||
clickPosition.z = 0f;
|
||||
@@ -358,12 +364,6 @@ public class GamePlayer : MonoBehaviour
|
||||
ClampPosition(screenWidth, bird);
|
||||
if (Application.isMobilePlatform)
|
||||
{
|
||||
GameObject leftArrow = GameObject.Find("LeftArrow");
|
||||
GameObject rightArrow = GameObject.Find("RightArrow");
|
||||
GameObject jumpArrow = GameObject.Find("JumpArrow");
|
||||
GameObject restartButton = GameObject.Find("RestartButton");
|
||||
GameObject backButton = GameObject.Find("BackButton");
|
||||
|
||||
leftArrow.transform.position = new UnityEngine.Vector3(-screenWidth / 2.5f, -4f, 0f);
|
||||
rightArrow.transform.position = new UnityEngine.Vector3(screenWidth / 2.5f, -4f, 0f);
|
||||
restartButton.transform.position = new UnityEngine.Vector3(screenWidth / 2.3f, Camera.main.orthographicSize - 1.2f, 0f);
|
||||
@@ -534,13 +534,12 @@ public class GamePlayer : MonoBehaviour
|
||||
}
|
||||
PlayerPrefs.SetString("HighScoreV2", highscore.ToString());
|
||||
PlayerPrefs.Save();
|
||||
scoreText.text = "Score: " + score;
|
||||
highScoreText.text = "High Score: " + highscore;
|
||||
scoreText.text = "Score: " + Tools.FormatWithCommas(score);
|
||||
highScoreText.text = "High Score: " + Tools.FormatWithCommas(highscore);
|
||||
}
|
||||
|
||||
void CheckIfGrounded()
|
||||
{
|
||||
GameObject jumpArrow = GameObject.Find("JumpArrow");
|
||||
isGrounded = bird.transform.position.y <= -4.1299996f;
|
||||
|
||||
rb.gravityScale = isGrounded ? 0f : 1.5f;
|
||||
|
||||
@@ -54,7 +54,8 @@ public class LeaderboardsMenu : MonoBehaviour
|
||||
UpdateStatus(false);
|
||||
string response = request.downloadHandler.text;
|
||||
var splitResponse = response.Split(';');
|
||||
for (int i = 0; i < splitResponse.Length; i++) {
|
||||
for (int i = 0; i < splitResponse.Length; i++)
|
||||
{
|
||||
var entry = splitResponse[i];
|
||||
var split = entry.Split(":");
|
||||
var username = Encoding.UTF8.GetString(Convert.FromBase64String(split[0]));
|
||||
@@ -70,7 +71,7 @@ public class LeaderboardsMenu : MonoBehaviour
|
||||
var highScoreText = entryInfo.transform.GetChild(1).GetComponent<TMP_Text>();
|
||||
|
||||
usernameText.text = $"{username} (#{i + 1})";
|
||||
highScoreText.text += highScore;
|
||||
highScoreText.text += Tools.FormatWithCommas(highScore);
|
||||
playerIcon.sprite = Resources.Load<Sprite>("Icons/Icons/bird_" + icon);
|
||||
if (icon == "1")
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using System.Numerics;
|
||||
using UnityEngine;
|
||||
|
||||
public static class Tools
|
||||
{
|
||||
@@ -15,9 +16,28 @@ public static class Tools
|
||||
else if (user == 4)
|
||||
{
|
||||
return Resources.Load<Sprite>("Icons/Icons/bird_-3");
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
return Resources.Load<Sprite>("Icons/Icons/bird_1");
|
||||
}
|
||||
}
|
||||
|
||||
public static string FormatWithCommas(string number)
|
||||
{
|
||||
try
|
||||
{
|
||||
BigInteger bigInt = BigInteger.Parse(number);
|
||||
return FormatWithCommas(bigInt);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return number;
|
||||
}
|
||||
}
|
||||
|
||||
public static string FormatWithCommas(BigInteger number)
|
||||
{
|
||||
return string.Format("{0:N0}", number);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user