-2
這是我的代碼要重新啓動遊戲團結框架點擊一個按鈕
void Start() {
GetComponent<SpriteRenderer>().enabled = false;
animator = transform.GetComponentInChildren<Animator>();
if (animator == null) {
Debug.LogError("Didn't find animator");
}
}
}
GetComponent<Rigidbody2D>().AddForce(Vector2.right * forwardSpeed);
if (didFlap) {
GetComponent<Rigidbody2D>().AddForce (Vector2.up * flapSpeed);
animator.SetTrigger("Doflap");
didFlap = false;
time = 0;
}
// Do graphics & input update
void Update(){
if(Input.GetKeyDown(KeyCode.Space) || (Input.GetMouseButtonDown(0))){
didFlap=true;
}
}
public void TakeDamage(float tim) {
Application.LoadLevel(Application.loadedLevel);
}
// Do physics engine update
void FixedUpdate() {
if (dead) {
Time.timeScale = 0;
GetComponent<SpriteRenderer>().enabled = true;
if(Time.timeScale == 0 && (Input.GetKeyDown (KeyCode.Space) || Input.GetMouseButtonDown (0))){
Application.LoadLevel(Application.loadedLevel);
這裏的時候,我給線(Application.LoadLevel(Application.loadedLevel))當我給它裏面,如果它不工作..在遊戲死亡我設置Time.timeScale爲0,並重新啓動按鈕出現在屏幕上。再次觸摸我需要重新啓動。但是當我給代碼重新啓動如果它沒有工作,如果遊戲突然重新啓動後沒有給出一個空間來點擊重啓按鈕,那麼當我給出它時不會出現。 我需要重新啓動按鈕點擊
}
}
void OnCollisionEnter2D(Collision2D collision){
animator.SetTrigger("Death");
dead = true;
}
}
請格式化您的代碼。現在很糟糕 – Backs