2
你好,我想创建像flappy鸟一样的徽章,我把图像放在像GameObjects这样的UI图像中。但它只显示3张图片的一张图片,请帮助!而高分的作品,当我获得更高的分数,但不知道为什么图像不会改变:(Unity High_Score徽章C#
对不起,我的英文不好
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);
}
}
图像,你可以看到我的GameObjects等它重写
我更新的代码,但仍不起作用
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);
}
}
}
我在看YouTube视频,并且正在检查如何获得奖牌,并且我是新手团结的,以后我会检查你的代码,希望它能起作用 –
你的任何'else if'子句都不会执行。 –