void OnCollisionEnter2D(Collision2D other) { Enemy enemy = other.collider.GetComponent <Enemy>(); EnemyShipType1 ship2 = other.collider.GetComponent <EnemyShipType1>(); EnemyPlane_01 plane1 = other.collider.GetComponent <EnemyPlane_01>(); EnemyPlane_02 plane2 = other.collider.GetComponent <EnemyPlane_02>(); EnemyBoss plane3 = other.collider.GetComponent <EnemyBoss>(); if (enemy != null) { enemy.ChangeHealth(hurt); Debug.Log("enemy health" + enemy.health); } if (ship2 != null) { ship2.ChangeHealth(hurt); Debug.Log("ship2 health" + ship2.health); } if (plane1 != null) { plane1.ChangeHealth(hurt); } if (plane2 != null) { plane2.ChangeHealth(hurt); } if (plane3 != null) { plane3.ChangeHealth(hurt); } animator.SetBool("ishit", true); rigidbody2d.simulated = false; timer = 0.5f; }
void OnTriggerStay2D(Collider2D other) { Enemy enemy = other.GetComponent <Enemy>(); EnemyShipType1 ship2 = other.GetComponent <EnemyShipType1>(); EnemyPlane_01 plane1 = other.GetComponent <EnemyPlane_01>(); EnemyBoss boss = other.GetComponent <EnemyBoss>(); EnemyPlane_02 plane2 = other.GetComponent <EnemyPlane_02>(); if (enemy != null) { enemy.ChangeHealth(hurt); } if (ship2 != null) { ship2.ChangeHealth(hurt); } if (plane1 != null) { plane1.ChangeHealth(hurt); } if (plane2 != null) { plane2.ChangeHealth(hurt); } if (boss != null) { boss.ChangeHealth(hurt); } }
// Update is called once per frame void Update() { if (iswin) { countdowner -= Time.deltaTime; if (countdowner < 0) { PlaySound(2); Pause(); countdowner = 1000000000f; } if (Input.GetKeyDown(KeyCode.P)) { Resume(); imgmode = true; MapMovedown.instance.speed = 1.3f; } if (timer_song < 0 && imgmode) { PlaySound(3); timer_song = timesong; } timer_song -= Time.deltaTime; return; } Vector2 region = gameCtr.object1.position; if (Bosstime < 0) { Vector2 planepos = region + Vector2.up * 8.5f; GameObject boss = Instantiate(Boss, planepos, Quaternion.identity); EnemyBoss newplane1 = boss.GetComponent <EnemyBoss>(); Bosstime = 1000000f; } if (Bosstime < 12f) { haveboss = true; if (!haveplayed) { PlaySound(1); haveplayed = true; } } if (timer_type1 < 0 && !haveboss) { Vector2 newpos1 = region + Vector2.right * Random.Range(-hrz_range, hrz_range) + Vector2.up * 8.0f; GameObject enemy1 = Instantiate(type1, newpos1, Quaternion.identity); Enemy new_enemy1 = enemy1.GetComponent <Enemy>(); timer_type1 = Random.Range(SummonTime_floor_1, SummonTime_ceiling_1); } if (timer_type2 < 0 && !haveboss) { Vector2 newpos2 = region + Vector2.up * Random.Range(4, vet_range) + Vector2.right * 3.8f; GameObject enemy2 = Instantiate(type2, newpos2, Quaternion.identity); EnemyShipType1 new_enemy2 = enemy2.GetComponent <EnemyShipType1>(); timer_type2 = Random.Range(SummonTime_floor_2, SummonTime_ceiling_2); } if (timer_plane1 < 0 && !haveboss) { Vector2 planepos = region + Vector2.up * 8.0f; GameObject plane1 = Instantiate(Planetype1, planepos, Quaternion.identity); EnemyPlane_01 newplane1 = plane1.GetComponent <EnemyPlane_01>(); timer_plane1 = Summonplane1time; } if (timer_littleboss < 0) { Vector2 planepos1 = region + Vector2.up * 8.0f + Vector2.right * 1.0f; Vector2 planepos2 = region + Vector2.up * 8.0f + Vector2.left * 1.0f; GameObject plane1 = Instantiate(Planetype2, planepos1, Quaternion.identity); EnemyPlane_02 newplane1 = plane1.GetComponent <EnemyPlane_02>(); GameObject plane2 = Instantiate(Planetype2, planepos2, Quaternion.identity); EnemyPlane_02 newplane2 = plane2.GetComponent <EnemyPlane_02>(); Summonlittleboss -= 50f; timer_littleboss = Summonlittleboss; if (Summonlittleboss < 60f) { Summonlittleboss = 10000f; } } if (timer_littleboss_one < 0) { Vector2 planepos1 = region + Vector2.up * 8.0f; GameObject plane1 = Instantiate(Planetype2, planepos1, Quaternion.identity); EnemyPlane_02 newplane1 = plane1.GetComponent <EnemyPlane_02>(); timer_littleboss_one = 100000f; } timer_type1 -= Time.deltaTime; timer_type2 -= Time.deltaTime; timer_plane1 -= Time.deltaTime; timer_littleboss_one -= Time.deltaTime; timer_littleboss -= Time.deltaTime; Bosstime -= Time.deltaTime; }