控制分数的显示
public class GameManager : MonoBehaviour
{
private Transform StartPoint;//针的发射点
private Transform SpawnPoint;//针的生成点
public GameObject pinPrefab;//针的预设物,需要拖拽
private Pin currentPin;//获取当前针,以方便调用方法
private bool isGameOver = false;//判定游戏是否结束
private int score = 0;
public Text scoreText;//控制分数的显示
void Start ()
{
StartPoint = GameObject.Find("StartPoint").transform;
SpawnPoint = GameObject.Find("SpawnPoint").transform;
SpawnPin();
}
private void Update()
{
if (isGameOver) return;//控制针的生成和发射
if (Input.GetMouseButtonDown(0))
{
score++;
scoreText.text = score.ToString();
currentPin.StartFly();//调用飞行的方法
SpawnPin();
}
}
void SpawnPin()
{
currentPin= GameObject.Instantiate(pinPrefab,SpawnPoint.position,pinPrefab.transform.rotation).GetComponent<Pin>();
}
public void GameOver()
{
if (isGameOver) return;//保证这个方法只执行一次
GameObject.Find("Circle").GetComponent<RotateSelf>().enabled = false;
isGameOver = true;
}
}