| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System;
- public class GameController : MonoBehaviour
- {
- public AimCrossHair[] aimCrossHairs;
- [NonSerialized] public float[] scores;
- [NonSerialized] public float time;
- [NonSerialized] public bool gameStart = false;
- [NonSerialized] public bool gameOver = false;
- [NonSerialized] public float targetDistance;
- public GameObject arrowPrefab;
- public GameObject arrowSecondPrefab;
- public static GameController ins;
- void Start()
- {
- ins = this;
- InitGame();
- InitDistanceSelectView();
- SetDisplayDistanceSelectView(true);
- }
- void Update()
- {
- if (gameStart && !gameOver)
- {
- if (time > 0) time -= Time.deltaTime;
- else
- {
- time = 0;
- gameOver = true;
- //添加结算界面
- transform.Find("PKGameSettleView").gameObject.SetActive(true);
- }
- }
- }
- public void HitTarget(float score, int playerIndex = -1)
- {
- if (!gameStart || gameOver) return;
- if (playerIndex >= 0)
- {
- scores[playerIndex] += score;
- HitTargetNumberNew.Create(score, playerIndex);
- }
- }
- private void InitDistanceSelectView()
- {
- DistanceSelectView distanceSelectView = transform.Find("DistanceSelectView").GetComponent<DistanceSelectView>();
- distanceSelectView.OnClickSelectDistance = HandleSelectDistance;
- }
- public void SetDisplayDistanceSelectView(bool active)
- {
- transform.Find("DistanceSelectView").gameObject.SetActive(active);
- }
- public void HandleSelectDistance(float distance)
- {
- SetDisplayDistanceSelectView(false);
- targetDistance = distance;
- foreach (var item in FindObjectsOfType<TargetBodyNew>()) item.SetDistance(distance);
- StartGame();
- }
- public void InitGame()
- {
- scores = new float[] { 0, 0 };
- time = 60;
- gameStart = false;
- gameOver = false;
- foreach (var item in FindObjectsOfType<ArrowNew>())
- {
- if (item && item.gameObject) Destroy(item.gameObject);
- }
- foreach (var item in FindObjectsOfType<PointSignLastHit>())
- {
- if (item) item.Hide();
- }
- }
- public void StartGame()
- {
- gameStart = true;
- }
- }
|