Unity Webサイトのチュートリアルでロールボールのようなゲームを構築していますが、今はゲームオーバーメニューに焦点を当てています。プレイヤーはすべての命を失います。 yesとnoのテキストと、デフォルトでyesのテキストの後ろに表示されているrawImageは、yesのテキストの後ろにあるイメージをnoに、矢印のキーでyesにしたいと思っています。私はキーで正しく実装したと思いますが、これを構築するにはコルーチンを必要としているように感じます。ユーザー入力を待たずにゲームオーバー機能が残っているので、これをどうすれば正しいモードで構築できますか?Unity Coroutine for gameMenu
私は、現時点ではこれをしなかった:
public class Manager : MonoBehaviour {
private float checkPoint = 0;
public GameObject Ball;
private GameObject cam;
private Object newBall;
public int lifes;
public Text Lifetext;
private bool gameIsOver = false;
private Text gameOver;
private Text playAgain;
private Text yes;
private Text no;
private RawImage TopMenuBall;
void Awake(){
Lifetext = GameObject.Find("Lifes").GetComponent<Text>();
gameOver = GameObject.Find("GameOver").GetComponent<Text>();
playAgain = GameObject.Find("PlayAgain").GetComponent<Text>();
yes = GameObject.Find("Yes").GetComponent<Text>();
no = GameObject.Find("No").GetComponent<Text>();
TopMenuBall = GameObject.Find("TopMenuBall").GetComponent<RawImage>();
gameOver.enabled = false;
playAgain.enabled = false;
yes.enabled = false;
no.enabled = false;
TopMenuBall.enabled = false;
TopMenuBall.transform.localPosition = new Vector3(-68,-41,0);
}
void Start(){
lifes = 3;
Lifetext.text = " x" + lifes;
SpawnBall();
cam = GameObject.Find ("Main Camera");
}
public void LifeUp(){
lifes++;
Lifetext.text = "X " + lifes;
}
public void LifeDown(){
if (lifes <= 0) {
GameOver();
} else {
lifes--;
Lifetext.text = "X " + lifes;
}
}
public void GameOver(){
Debug.Log ("gameover");
gameOver.enabled = true;
playAgain.enabled = true;
yes.enabled = true;
no.enabled = true;
TopMenuBall.enabled = true;
if (Input.GetKeyDown (KeyCode.DownArrow)) {
TopMenuBall.transform.localPosition = new Vector3 (-68, -82, 0);
Debug.Log ("up");
}
else if (Input.GetKeyDown(KeyCode.UpArrow))
TopMenuBall.transform.localPosition = new Vector3(-68,-41,0);
}
void SpawnBall(){
Vector3 spawnPosition = new Vector3 (0.02f,1.4f,-39f);
Quaternion spawnRotation = Quaternion.identity;
newBall = Instantiate (Ball, spawnPosition, spawnRotation);
Camera.main.GetComponent<cameraMove>().player = (GameObject)newBall;
}
ユーザーは、それがゲームオーバー機能に入り、問題があるすべての静物を失うとき、どのように私はこの問題を解決することができますか?
なぜcorotine?単に 'Vector3.Lerp'を使って画像を移動することができます。 –
私はマージャーでそれをしたい、どうすればいい? –