using System.Collections; using System.Collections.Generic; using UnityEngine; public class GameController : MonoBehaviour { [Tooltip("玩家预设")] public GameObject prefabP; [Tooltip("怪物预设")] public GameObject prefabM; public GameObject[] sceneEnity; public GameObject[] player; public GameObject[] moster; private List playerS; private List mosterS; public Transform Bullet; public Transform Moster; public Transform Player; public GameObject bulletG; public GameObject bulletR; private static GameController instance; void Awake() { if (instance==null) { instance = this; } playerS = new List(); mosterS = new List(); for (int i = 0; i < player.Length; i++) { var ps= player[i].GetComponent(); if (ps) { playerS.Add(ps); } } for (int i = 0; i < moster.Length; i++) { var ms = moster[i].GetComponent(); if (ms) { mosterS.Add(ms); } } } public static GameController GetInstance() { return instance; } private Vector3 nowPos; private Vector3 oldPos; private bool isClick = false; private float length = 1; //private void OnMouseUp() //{ // isClick = false; // print(2); //} //private void OnMouseDown() //{ // isClick = true; // print(3); //} private void Update() { CloneRole(); WriteFile(); if (Input.GetMouseButtonDown(0)) { isClick = true; } else if(Input.GetMouseButtonUp(0)) { isClick = false; } nowPos = Input.mousePosition; if (isClick == true) { Vector3 offset = nowPos - oldPos; if (Mathf.Abs(offset.x) > Mathf.Abs(offset.y) && Mathf.Abs(offset.x) > length) { // transform.Rotate(Vector3.up, -offset.x); Rotation(-offset.x/10); print(111); } } oldPos = Input.mousePosition; } private void Rotation(float offset) { for (int i = 0; i < playerS.Count; i++) { playerS[i].RotationSelf(offset); } for (int i = 0; i < mosterS.Count; i++) { mosterS[i].RotationSelf(offset); } } private void CloneRole() { if (Input.GetKeyDown(KeyCode.P)) { var go = GameObject.Instantiate(prefabP); go.transform.SetParent(Player); go.name = prefabP.name; var gs= go.AddComponent(); playerS.Add(gs); } if (Input.GetKeyDown(KeyCode.M)) { var go = GameObject.Instantiate(prefabM); go.transform.SetParent(Moster); go.name = prefabM.name; var gs = go.AddComponent(); mosterS.Add(gs); } } private void WriteFile() { if (Input.GetKeyDown(KeyCode.C)) { OutPointManager.GetInstance().StartWriteFile(); } } public float GetAng(Vector3 dir) { var xx = Mathf.Abs(dir.x); var zz = Mathf.Abs(dir.z); var obl = Mathf.Sqrt(Mathf.Pow(dir.x, 2) + Mathf.Pow(dir.z, 2)); return 180 / Mathf.PI * Mathf.Acos(xx / obl); } }