【发布时间】:2016-04-03 16:25:46
【问题描述】:
前几天我开始使用Unity,使用官方教程学习。我已经完成了第一场比赛,并且开始喜欢编程。我对此很陌生,并且认为如果我将这些教程游戏做得更好,它将对我有所帮助。一切都很顺利,但现在我被困住了。我想要一个在我赢得比赛时出现的菜单。我制作了菜单,它有 3 个按钮(“再试一次”、“菜单”和“退出”)。这是一张图片:http://prntscr.com/9jy71h。这些按钮可以工作,但我唯一的问题是它们在整个游戏中都出现了很长时间,而我只想要它们在最后。我尝试了很多,但我似乎一直得到这个错误:'Retry' doesn't exist in the current context.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
public Text countText;
public Text winText;
private Rigidbody rb;
private int count;
void Start ()
// The game starts here.
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText ();
winText.text = "";
Retry.GameObject.SetActive(false);
Menu.GameObject.SetActive(false);
Exit.GameObject.SetActive(false);
}
void FixedUpdate ()
// Movement.
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
void OnTriggerEnter(Collider other)
// Picking things up and count score.
{
if (other.gameObject.CompareTag("Pick Up"))
{
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = "Count:" + count.ToString ();
if (count >= 12)
// End of the game, you won.
{
winText.text = "You win!";
Retry.GameObject.SetActive(true);
Menu.GameObject.SetActive(true);
Exit.GameObject.SetActive(true);
}
}
}
为什么他不能识别我制作的游戏对象? (您在图片上看到的按钮)抱歉我的英语不好,感谢您抽出宝贵时间阅读此内容并尽可能回答。
编辑:http://prntscr.com/9jybke 这些都是错误。但是,如果我删除顶部和底部的 6 条 gameobjective(bool) 行,它工作正常,但我一直打开菜单。
【问题讨论】:
-
也许这会对你有所帮助? :answers.unity3d.com/questions/8610/…
-
非常感谢!我会用这个方法:D
标签: c# user-interface unity3d