void spawn() { TerrainInfo info = GameObject.Find("Terrain").GetComponent <TerrainInfo>(); Vector2 mapPos = info.getPos(); Vector2 mapSize = info.getSize(); int n = 10; for (int i = 0; i < n; i++) { float z = 0f, rot = 0f; int player = i % 2; if (player == 0) { z = mapPos.y + mapSize.y * 0.1f; rot = 0f; } else { z = mapPos.y + mapSize.y * 0.9f; rot = 180f; } Vector3 spawnPosition = new Vector3(mapPos.x + mapSize.x * (0.25f + 0.5f * i / n), 0f, z); Quaternion spawnRotation = Quaternion.Euler(0.0f, rot, 0.0f); if (i < 2) { spawnJeep(spawnPosition, spawnRotation, player); } else if (i < 6) { spawnTank(spawnPosition, spawnRotation, player); } else if (i < 8) { spawnCopter(spawnPosition, spawnRotation, player); } else { spawnAntiair(spawnPosition, spawnRotation, player); } } }
protected Vector3 getRandomTargetPos(float minHeight = 0f, float maxHeight = 0f) { float maxDot = -1f; Vector3 targetPos = new Vector3(); for (int i = 0; i < 5; i++) { TerrainInfo info = GameObject.Find("Terrain").GetComponent <TerrainInfo>(); Vector3 mapPos = info.getPos(); Vector3 mapSize = info.getSize(); Vector3 pos = new Vector3(Random.Range(mapPos.x + mapSize.x * 0.2f, mapPos.x + mapSize.x * 0.8f), Random.Range(minHeight, maxHeight), Random.Range(mapPos.y + mapSize.y * 0.2f, mapPos.y + mapSize.y * 0.8f)); Vector3 direction = (pos - transform.position).normalized; float dot = Vector3.Dot(transform.forward, direction); if (dot > maxDot) { maxDot = dot; targetPos = pos; } } return(targetPos); }