Bool是真的,对象不会移动?

时间:2017-08-19 00:47:19

标签: c#

我想要我的游戏,所以当游戏开始时,它会说“别触摸墙壁!”然后倒数到0,然后消失。我也想要它让玩家在击中0之前不能移动。它是pacman-esque,因此玩家总是在移动。当计数器击中0时文本消失,但玩家在此之前移动。 代码:

public class Movement : MonoBehaviour {
float speed = 0.1f;
int direction = 0;
public GameObject eventHandler;
private EventStuff eventHandlerScript;
public bool start = false;






// Use this for initialization
void Start () {
    eventHandlerScript = eventHandler.GetComponent<EventStuff>();
    start = eventHandlerScript.gameStart;


}

// Update is called once per frame
void Update () {
    start = eventHandlerScript.gameStart;
    if (start = true) {
        //The movement Code is here
    }


}

}

隐形数据处理程序:

public class EventStuff : MonoBehaviour {
public Text DontTouch;
public Text Counter;
public float timer = 1f;
public bool gameStart = false;
// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
    timer++;
    if (timer < 60) {
        Debug.Log ("3");
    } else if (timer < 120) {
        Counter.text = ("2");
        Debug.Log ("2");
    } else if (timer < 180) {
        Counter.text = ("1");
        Debug.Log ("1");
    }
    else if(timer > 180) {

    Destroy(Counter);
    Destroy(DontTouch);
        gameStart = true;
        Debug.Log ("start!");
    }

}

}

1 个答案:

答案 0 :(得分:0)

而不是

if (start = true) {

你应该写

if (start == true) {

或更好的简单

if (start) {