using System.Collections; using System.Collections.Generic; using UnityEngine; using Cinemachine; using UnityEngine.UI; public class GameManager : MonoSingleton { public GameObject GameEndTip; public GameObject greenPerson; public GameObject person2; public GameObject[] needRemoveObjs; public GameObject[] needTransferObjs; public GameObject errorTip; bool safe; public bool remove=false; public int safeOperate;//玩家选择的对应操作,0对应转移,1对应清理 RaycastHit rh; protected override void Awake() { base.Awake(); DontDestroyOnLoad(gameObject); safe = Random.Range(0,1f) > 0.5 ? true : false; InitScene(safe); } private void Start() { } private void Update() { if (remove) { Ray ray=Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out rh)) { if (rh.collider.tag == "ZAW" && Input.GetMouseButtonDown(0)) { if (rh.collider.GetComponent()) { rh.collider.GetComponent().SetTrigger("Sankai"); } else { rh.collider.gameObject.SetActive(false); } rh.collider.tag = "Untagged"; } } } } public void InitScene(bool safe) { greenPerson.GetComponent().SetPosBySafe(safe); if (!safe) { foreach (GameObject obj in needRemoveObjs) { obj.SetActive(true); } greenPerson.tag = "ZAW"; } } public void PanDuanSafe(bool safe) { EventManager.Instance.emit("PanDuanSafe", this.safe == safe,this.safe); } public void SetSafeOperate(int index) { safeOperate = index; if (index == 0) { EventManager.Instance.emit("SafeOperate",0); Invoke("TransferObjs", 1); } else if (index==1) { greenPerson.tag = "ZAW"; remove = true; EventManager.Instance.emit("SafeOperate",1); } } void TransferObjs() { person2.SetActive(true); greenPerson.GetComponent().SetPosBySafe(true); FindObjectOfType().LookAt = needTransferObjs[0].transform; FindObjectOfType().Follow = needTransferObjs[0].transform; FindObjectOfType().m_YAxis.Value = 0.75f; FindObjectOfType().m_XAxis.Value = 56.27f; foreach (GameObject obj in needTransferObjs) { obj.transform.position += new Vector3(2, 0, -35); } GameObject obj2 = Instantiate(Resources.Load("operate")); obj2.GetComponent().str = "2-将被救者转移到安全位置"; Invoke("ZhuanyiEnd",2); } void ZhuanyiEnd() { errorTip.SetActive(true); errorTip.GetComponentInChildren().InitThis("恭喜通关", 60); GameEndTip.SetActive(true); GameEndTip.GetComponentInChildren().text="已成功转移到安全位置"; EduCoderTool.WebConnecter.Singleton.SendResultToWeb(true); } }