void OnTriggerEnter2D(Collider2D coll) { // if(SceneManager.GetActiveScene().name == "play"){ if (coll.gameObject.tag == "Obstacle") { ObstacleChildBehaviour obs = coll.gameObject.GetComponent <ObstacleChildBehaviour>() as ObstacleChildBehaviour; if (!obs.GetPassable())//obstacle is not passable { if (SceneManager.GetActiveScene().name == "tutorial") {// if tutorial is ongoing GameObject p = Instantiate(playerExplosionParticles, this.transform.position, this.transform.rotation); Destroy(p, 3); TutorialManager tm = GameObject.Find("TutorialManager").GetComponent <TutorialManager>(); smashCount = 0; tm.RestartObstaclesTutorial(); return; } if (PowerUpManager.powerUpActive == false) { //kill the player GameObject p = Instantiate(playerExplosionParticles, this.transform.position, this.transform.rotation); Destroy(p, 3); GameManager g = GameObject.Find("GameManager").GetComponent <GameManager>(); g.EndGame(); } else { //player still has life, because power up is active thus disable the powerup Destroy(Instantiate(obstacleBurst, obs.transform.position, obs.transform.rotation), 1.5f); obs.gameObject.SetActive(false); powerUpManager.DisableAdvantages(); GameManager.IncreaseScore(1); } } else { //obstacle is passable if (SceneManager.GetActiveScene().name == "tutorial") { //if tutorial is ongoing smashCount++; if (smashCount >= 5) { TutorialManager tm = GameObject.Find("TutorialManager").GetComponent <TutorialManager>(); tm.EndTutorial(); } } Destroy(Instantiate(obstacleBurst, obs.transform.position, obs.transform.rotation), 1.5f); obs.gameObject.SetActive(false); GameManager.IncreaseScore(1); } } else if (coll.gameObject.tag == "PowerUp") { //player has collided with a power up GetComponent <AudioSource>().PlayOneShot(powerUpAudioClip); coll.gameObject.SetActive(false); powerUpManager.ActivatePowerUp(); Destroy(coll.gameObject); } }
void resetPassableChild(int i, int passableChildIndex) { for (int j = 0; j < 3; j++) { obstacleChild = obstacles[i].transform.GetChild(j).gameObject.GetComponent <ObstacleChildBehaviour>() as ObstacleChildBehaviour; if (j == passableChildIndex) { obstacleChild.SetPassable(true); } else { obstacleChild.SetPassable(false); } obstacleChild.gameObject.SetActive(true); } }
private void resetVelocities(int i) { float angularVelocity = Random.Range(angularVelocityChildObs - 20, angularVelocityChildObs); angularVelocity *= Random.Range(-1, 2) >= 0 ? 1 : -1; for (int k = 0; k < 3; k++) { //obstacleChild.transform.rotation = Quaternion.Euler(0,0,Random.Range(0,360)); obstacleChild = obstacles[i].transform.GetChild(k).gameObject.GetComponent <ObstacleChildBehaviour>() as ObstacleChildBehaviour; obstacleChild.angularVelocity = angularVelocity; } if (SceneManager.GetActiveScene().name == "play") { obstacles[i].GetComponent <Rigidbody2D>().velocity = new Vector2(0, -GameManager.speed); } else { obstacles[i].GetComponent <Rigidbody2D>().velocity = new Vector2(0, -TutorialManager.speed); } }