/// <summary> /// 初始化:随机生成一批灰球和黑球 /// TODO:生成的位置随机性不够 /// </summary> private void InitializeBalls() { //生成一堆灰球黑球 RaycastHit hit; int range = 5; //UnityEngine.Debug.LogFormat("灰{0},黑{1}", greyNum, blackNum); for (int i = 0; i < newGreyNum; i++) { Vector3 pos = new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f)).normalized *Random.Range(rangeMin + range, rangeMax - range); pos = new Vector3(pos.x, 0.5f, pos.z); // Vector3 dir = new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f)).normalized * (Random.Range(rangeMin+ range, rangeMax- range) + range); Vector3 dir = new Vector3(pos.x, 0, pos.z).normalized *Random.Range(rangeMax - range, rangeMax); if (Physics.Raycast(pos, dir, out hit, 40, 1 << 10)) { // UnityEngine.Debug.Log("射中"); Hostage.GenerateSelf(hit.point - dir.normalized * greyBallR); } else { Hostage.GenerateSelf(pos + dir); // UnityEngine. Debug.LogFormat("未射中,{0},{1},{2}", pos , dir,pos+dir); } } for (int i = 0; i < newBlackNum; i++) { Vector3 pos = new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f)).normalized *Random.Range(rangeMin + range, rangeMax - range); pos = new Vector3(pos.x, 0.5f, pos.z); // Vector3 dir = new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f)).normalized * (Random.Range(rangeMin+ range, rangeMax- range) + range); Vector3 dir = new Vector3(pos.x, 0, pos.z).normalized *Random.Range(rangeMax - range, rangeMax); if (Physics.Raycast(pos, dir, out hit, 40, 1 << 10)) { // Debug.Log("射中"); Enemy.GenerateSelf(hit.point - dir.normalized * blackBallR); } else { Enemy.GenerateSelf(pos + dir); // Debug.LogFormat("未射中,{0}",pos + dir); } } }
void Red2Grey() { DestroySelf(); Hostage.GenerateSelf(transform.position); }