public void Break(bool scorePoints) { AsterInfo info = new AsterInfo(); info.level = level + 1; info.position = transform.position; Debug.Log("asteroid hit. Level:" + level); if (level < 3) { GameObject g = this.transform.parent.gameObject; //Debug.Log(g); g.GetComponent <AsteroidController>().NewAsteroid(info); } else { // Instantiate(finalExplosion, transform.position, Quaternion.identity); } if (scorePoints) { GameObject g; g = this.transform.parent.gameObject; g.GetComponent <AsteroidController>().SendMessage("ScoreAsteroid", info.level - 1); } Explode(); }
void Break(bool scorePoints) { if (level < 3) { AsterInfo info = new AsterInfo(); info.level = level + 1; info.position = transform.position; // break into a number of smaller units (level=level+1) //if (level == 2 && Random.Range(0, 3) < 1) { // GameObject.Find("GameController").SendMessage("NewAsteroid", info); // GameObject.Find("GameController").SendMessage("NewAsteroid", info); // GameObject.Find("GameController").SendMessage("NewPowerup", info); //} //else { GameObject.Find("GameController").SendMessage("NewAsteroid", info); GameObject.Find("GameController").SendMessage("NewAsteroid", info); GameObject.Find("GameController").SendMessage("NewAsteroid", info); //} } else { Instantiate(finalExplosion, transform.position, Quaternion.identity); } if (scorePoints) { GameObject.Find("GameController").SendMessage("ScoreAsteroid", level); } Explode(); }
void NewPowerup(AsterInfo info) { numAsteroids += 1; // its fine to count this as an asteroid // random motion is imparted when the new obstacle calls Start() Instantiate( powerups[Random.Range(0, powerups.Length)], info.position, Random.rotation); }
void NewAsteroid(AsterInfo info) { numAsteroids += 1; // random motion is imparted when the new obstacle calls Start() GameObject obstacle = Instantiate( obstacles[Random.Range(0, obstacles.Length)], info.position, Random.rotation) as GameObject; obstacle.SendMessage("SetLevel", info.level); }
public void NewAsteroid(AsterInfo info) { int aCount = 0; if (info.level == 1) { aCount = 1; } else { aCount = 2; } numAsteroids += aCount; for (int bCount = 0; bCount < aCount; bCount++) { // random motion is imparted when the new obstacle calls Start() Vector3 aOffset = new Vector3(0, 0, 0); if (info.level == 1) { aOffset = transform.position; } GameObject obstacle = Instantiate( obstacles[Random.Range(0, obstacles.Length)], info.position + aOffset, Random.rotation) as GameObject; obstacle.transform.parent = this.transform; obstacle.name = this.transform.name + "Asteroid" + numAsteroids; Debug.Log(this.name + "...initialize asteroid...parent:" + this.transform); float aScale = 0.1f; obstacle.transform.localScale = new Vector3(aScale, aScale, aScale); obstacle.transform.position = info.position + aOffset; obstacle.tag = "Asteroid"; float aRand = 5f * info.level; // float aRand = 25; Vector3 astVel = new Vector3(Random.Range(-aRand, aRand), Random.Range(-aRand, aRand), Random.Range(-aRand, aRand)); obstacle.GetComponent <Rigidbody>().velocity = astVel; obstacle.SendMessage("SetLevel", info.level); } }
void ReinitLevel() { numAsteroids = 0; newSaucerAllowed = true; GameObject player = GameObject.Find("PlayerShip"); currentLevel += 1; Debug.Log("Current Level " + currentLevel); int initialObstacles = getInitNumAsteroidsByLevel(currentLevel); Debug.Log("Initializing " + initialObstacles + " asteroids."); for (int i = 0; i < initialObstacles; i++) { // placed anywhere within edges but outside a specified radius from where the player is //GameObject.Find("edges"); // how can I get the params from inside "Edges"? float x, y; Vector3 delta; do { x = Random.Range(-16, 16); y = Random.Range(-9, 9); delta = player.transform.position - new Vector3(x, 0.0f, y); } while (delta.magnitude < 5); AsterInfo info = new AsterInfo(); info.level = 1; info.position = new Vector3(x, 0.0f, y); NewAsteroid(info); } levelStartTime = Time.time; ClearGameover(); UpdateScore(0); SpawnSaucerAfterRandomDelay(); }
public void ReinitLevel() { GameObject[] aster = GameObject.FindGameObjectsWithTag("Asteroid"); Debug.Log("num asteroids:" + aster.Length); foreach (GameObject ast in aster) { if (ast.transform.parent == this.transform) { Destroy(ast); } } GameObject[] saucer = GameObject.FindGameObjectsWithTag("Saucer"); foreach (GameObject ast in saucer) { if (ast.transform.parent == this.transform) { Destroy(ast); } } GameObject[] torp = GameObject.FindGameObjectsWithTag("enemyWeapon"); foreach (GameObject ast in torp) { if (ast.transform.parent == this.transform) { Destroy(ast); } } numAsteroids = 0; newSaucerAllowed = true; currentLevel += 1; Debug.Log("Current Level " + currentLevel); int initialObstacles = Random.Range(4, 6); Debug.Log(this.name + "...Initializing " + initialObstacles + " asteroids."); for (int i = 0; i < initialObstacles; i++) { // placed anywhere within edges but outside a specified radius from where the player is //GameObject.Find("edges"); // how can I get the params from inside "Edges"? float x = 0; float z = 0; bool keepGoing = true; while (keepGoing) { Vector3 delta; z = Random.Range(-15, 3); x = Random.Range(-15, 3); delta = player.transform.position - new Vector3(x, z, 0); if (delta.magnitude > 10) { keepGoing = false; } } AsterInfo info = new AsterInfo(); info.level = 1; info.position = new Vector3(0, x, z); //Debug.Log("new asteroid. x:" +x+ " z:" + z); NewAsteroid(info); } levelStartTime = Time.time; UpdateScore(0); SpawnSaucerAfterRandomDelay(); }