Unity High_Score Badges C #
Hallo Ich möchte Abzeichen wie in Flappy Bird erstellen und Bilder in UI-Bilder wie GameObjects einfügen. Aber es zeigt mir nur ein Bild von 3 Bildern. Und HighScore funktioniert, es wird neu geschrieben, wenn ich eine höhere Punktzahl erhalte, aber ich weiß nicht, warum sich die Bilder nicht ändern:
Entschuldige mein schlechtes Englisc
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ScoreManager : MonoBehaviour
{
private float score = 0f;
public Text Scoretext;
public MenuController deathmenu;
public GameObject IntroGUI, DeathGUI, Canvas;
public GameObject[] medals;
public GameObject medale;
void Start()
{
medale.SetActive(false);
foreach(GameObject m in medals)
{
m.SetActive(true);
}
}
void Update()
{
//handle back key in Windows Phone
if (Input.GetKeyDown(KeyCode.Escape))
Application.Quit();
if (GameStateManager.GameState == GameState.Intro)
{if (WasTouchedOrClicked())
{
GameStateManager.GameState = GameState.Playing;
IntroGUI.SetActive(false);
Canvas.SetActive(true);
}
}
else if (GameStateManager.GameState == GameState.Playing)
{
score += Time.deltaTime;
Scoretext.text = ((int)score).ToString();
if (PlayerPrefs.GetFloat("Highscore") < score)
PlayerPrefs.SetFloat("Highscore", score);
if(PlayerPrefs.GetFloat("Scoretext") > 0)
{
medals[0].SetActive(true);
}
else if
(PlayerPrefs.GetFloat("Scoretext") > 2)
{
medals[1].SetActive(true);
}
else if
(PlayerPrefs.GetFloat("Scoretext") > 5)
{
medals[2].SetActive(true);
}
medale.SetActive(true);
deathmenu.ToggleEndMenu(score);
}
}
m Bild sehen Sie meine GameObjects und so weiter.
Ich habe den Code aktualisiert, aber es funktioniert immer noch nicht
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ScoreManager : MonoBehaviour
{
private float score = 0f;
public Text Scoretext;
public MenuController deathmenu;
public GameObject IntroGUI, DeathGUI, Canvas;
public GameObject[] medals;
public GameObject medale;
void Start()
{
medale.SetActive(true);
}
void Update()
{
//handle back key in Windows Phone
if (Input.GetKeyDown(KeyCode.Escape))
Application.Quit();
if (GameStateManager.GameState == GameState.Intro)
{
if (WasTouchedOrClicked())
{
GameStateManager.GameState = GameState.Playing;
IntroGUI.SetActive(false);
Canvas.SetActive(true);
medale.SetActive(false);
}
}
else if (GameStateManager.GameState == GameState.Playing)
{
score += Time.deltaTime;
Scoretext.text = ((int)score).ToString();
if (PlayerPrefs.GetFloat("Highscore") < score)
PlayerPrefs.SetFloat("Highscore", score);
deathmenu.ToggleEndMenu(score);
}
}
void FixedUpdate()
{
//just jump up and down on intro screen
if (GameStateManager.GameState == GameState.Intro)
{
}
else if
(GameStateManager.GameState == GameState.Playing || GameStateManager.GameState == GameState.Dead)
{
}
}
bool WasTouchedOrClicked()
{
if (Input.GetButtonUp("Jump") || Input.GetMouseButtonDown(0) ||
(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began))
return true;
else
return false;
}
void OnCollisionEnter2D(Collision2D col)
{
if (GameStateManager.GameState == GameState.Playing)
{
if (col.gameObject.tag == "CARS")
{
PlayerDies();
}
}
}
void PlayerDies()
{
GameStateManager.GameState = GameState.Dead;
if (PlayerPrefs.GetFloat("Scoretext") > 0)
{
medals[0].SetActive(true);
}
else if
(PlayerPrefs.GetFloat("Scoretext") > 2)
{
medals[1].SetActive(true);
}
else if
(PlayerPrefs.GetFloat("Scoretext") > 5)
{
medals[2].SetActive(true);
}
}
}