using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using TMPro; //需要命名空间
public class gamecontroller : MonoBehaviour
{
// Start is called before the first frame update
public static gamecontroller instance;
public GameObject GmaeOverTxt;
public bool gameOver = false;
private TMP_Text textComponent; //定义一个text变量
public float scrollSpeed = -1.5f;
private int score = 0;
void Start()
{
}
void Awake()
{
if (instance == null) {
instance = this;
} else if (instance!=this) {
Destroy(gameObject);
}
}
public void BirdScored() {
if (gameOver) {
return;
}
score++;
textComponent = GameObject.Find("scoreTxt").GetComponent<TMP_Text>(); //scoreTxt是标签的命名
textComponent.text = "SCORE:" + score.ToString();//赋值动态文本
}
// Update is called once per frame
void Update()
{
if (gameOver==true&&Input.GetMouseButtonDown(0)) {
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
public void BirdDied() {
GmaeOverTxt.SetActive(true);
gameOver = true;
}
}