public void YellowBoost(int boostAmount) { WaveSpawnnerScript = GameObject.FindGameObjectWithTag("wave").GetComponent <WaveSpawnner>(); wavenumber = WaveSpawnnerScript.currentWaveIndex; if (wavenumber >= 1) { int randomNumber = Random.Range(0, 100); if (randomNumber < pickUpChance) { if (GameObject.FindGameObjectWithTag("Weapon").transform.name != "gun(Clone)") { pickups[1].transform.position = (GameObject.FindGameObjectWithTag("Player").transform.position + this.gameObject.transform.position) / 2; Instantiate(pickups[1], pickups[1].transform.position, transform.rotation); StartCoroutine(Scale(4.0f)); } } } if (GameObject.FindGameObjectWithTag("Weapon").transform.name == "gun(Clone)") { health -= boostAmount; Global.scorecount += boostAmount; if (health <= 0) { Destroy(gameObject); //orange wala prefab Instantiate(soundObject, transform.position, transform.rotation); } } }
public void TakeDamage(int damageAmount) { if (GameObject.FindGameObjectWithTag("Player")) { health -= damageAmount; Global.scorecount += damageAmount; mainweapon = GameObject.FindGameObjectWithTag("Weapon"); if (health <= 0) { WaveSpawnnerScript = GameObject.FindGameObjectWithTag("wave").GetComponent <WaveSpawnner>(); wavenumber = WaveSpawnnerScript.currentWaveIndex; index = 0; if (wavenumber == 0) { if (mainweapon.transform.name == "gun") { Destroy(gameObject); Instantiate(soundObject, transform.position, transform.rotation); } } if (wavenumber >= 1 && gameObject.transform.name != "smallDevil(Clone)") { int randomNumber = Random.Range(0, 101); if (randomNumber < pickUpChance) { if ((wavenumber == 1 && mainweapon.transform.name == "gun(Clone)") || (wavenumber == 1 && mainweapon.transform.name == "gun")) { pickups[0].transform.position = (GameObject.FindGameObjectWithTag("Player").transform.position + this.gameObject.transform.position) / 2; Instantiate(pickups[0], pickups[0].transform.position, transform.rotation);//gameObject.instantiate } else { char name = mainweapon.transform.name[7]; ind = System.Convert.ToInt32(name); //1 or 2 if (ind == 49) //pink rocket now, pick arrow or bow { if (gameObject.transform.name != "Sphere(Clone)") { randomPickup = pickups[Random.Range(1, pickups.Length - 1)]; randomPickup.transform.position = (GameObject.FindGameObjectWithTag("Player").transform.position + this.gameObject.transform.position) / 2; Instantiate(randomPickup, randomPickup.transform.position, transform.rotation); } } if (ind == 50)//arrow now, pick bow { randomPickup = pickups[2]; randomPickup.transform.position = (GameObject.FindGameObjectWithTag("Player").transform.position + this.gameObject.transform.position) / 2; Instantiate(randomPickup, transform.position, transform.rotation); } } } int randHealth = Random.Range(0, 101); playerScript = GameObject.FindGameObjectWithTag("Player").GetComponent <MyJoyStick>(); playerHealth = playerScript.health; if (randHealth < healthPickupChance) { if (scene.name == "SampleScene") { if (playerHealth < 8) { healthPickup.transform.position = this.gameObject.transform.position + new Vector3(6f, 1f, 0f); Instantiate(healthPickup, transform.position, transform.rotation); } } else { if (playerHealth < 10) { healthPickup.transform.position = this.gameObject.transform.position + new Vector3(6f, 1f, 0f); Instantiate(healthPickup, transform.position, transform.rotation); } } } Destroy(gameObject); Instantiate(soundObject, transform.position, transform.rotation); } } } }
//to detect collision..with enemy private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Enemy" && GameObject.FindGameObjectWithTag("Player") != null) { //Changes being made WaveSpawnnerScript = GameObject.FindGameObjectWithTag("wave").GetComponent <WaveSpawnner>(); wavenumber = WaveSpawnnerScript.currentWaveIndex; if (collision.GetComponent <OurEnemy>().transform.name == "smallDevil(Clone)" && GameObject.FindGameObjectWithTag("Player") != null) { if (GameObject.FindGameObjectWithTag("devil") == null) { if (GameObject.FindGameObjectsWithTag("Enemy").Length != 0) { GameObject[] allsmalldevils = GameObject.FindGameObjectsWithTag("Enemy"); foreach (GameObject child in allsmalldevils) { child.GetComponent <OurEnemy>().smallDevilHit(damage, collision, gameObject); } DestroyProjectile(); StartCoroutine(Order()); if (scene.name == "Level2") { screenTransition.LoadScene("Win2"); } else { screenTransition.LoadScene("Win"); } } if (scene.name == "Level2") { screenTransition.LoadScene("Win2"); } else { screenTransition.LoadScene("Win"); } } else { collision.GetComponent <OurEnemy>().smallDevilHit(damage, collision, gameObject); DestroyProjectile(); } } /* * collision.GetComponent<OurEnemy>().smallDevilHit(damage,collision,gameObject); * if(GameObject.FindGameObjectWithTag("devil")==null){ * if(GameObject.FindGameObjectsWithTag("Enemy").Length==0){ * * StartCoroutine(Order()); * screenTransition.LoadScene("Win"); * } * } * else{ * collision.GetComponent<OurEnemy>().smallDevilHit(damage,collision,gameObject); * DestroyProjectile(); * } * }*/ if (wavenumber >= 1) { if ((collision.GetComponent <OurEnemy>().transform.name == "Sphere(Clone)" || collision.GetComponent <OurEnemy>().transform.name == "Sphere2(Clone)") && GameObject.FindGameObjectWithTag("Weapon").transform.name != "gun" ) { //damage=1; collision.GetComponent <OurEnemy>().YellowBoost(damage); DestroyProjectile(); } else { collision.GetComponent <OurEnemy>().TakeDamage(damage); //collision.GetComponent<Enemy> loads the enemy script on //collision object and call the TakeDamage function of Enemy.cs DestroyProjectile(); } } else { if (!(collision.GetComponent <OurEnemy>().transform.name == "smallDevil(Clone)" && GameObject.FindGameObjectWithTag("Player") != null)) { collision.GetComponent <OurEnemy>().TakeDamage(damage); //collision.GetComponent<Enemy> loads the enemy script on //collision object and call the TakeDamage function of Enemy.cs DestroyProjectile(); } } } if (collision.tag == "devil" && GameObject.FindGameObjectWithTag("Player") != null) { collision.GetComponent <Devil>().TakeDamage(damage); prefab = (GameObject)Resources.Load("ToonExplosion/Prefabs/smallDevil", typeof(GameObject)); Instantiate(prefab, transform.position, Quaternion.identity); DestroyProjectile(); } if (collision.tag == "bomb" && GameObject.FindGameObjectWithTag("Player") != null) { explosion = (GameObject)Resources.Load("ToonExplosion/Prefabs/Explosion", typeof(GameObject)); Collider2D[] colliders = Physics2D.OverlapCircleAll(collision.gameObject.transform.position, 4.0f); foreach (Collider2D col in colliders) { if (col.tag == "Enemy") { Destroy(col.gameObject); } } Destroy(collision.gameObject); Instantiate(explosion, transform.position, Quaternion.identity); } }