void GetDamaged(Collider2D other) { int Damage = 1; if (other.name != "Environment Damage") { Damage_Script Dmg = other.gameObject.GetComponent <Damage_Script>(); Damage = Dmg.HitDamage; } if (HP != 0) { if (HP - Damage > 0) { HP -= Damage; } else { HP = 0; DEAD = 1; } } if (other.tag == "Bullet") { Vector2 BulletVel = other.gameObject.GetComponent <Rigidbody2D>().velocity; Rest = 0; Stun = 1; SelfRigid2D.velocity = BulletVel; Invoke("StunCool", 0.3f); Destroy(other.gameObject); } }
void ShotPlayer() { if ((Shooting == 0) && (Shooted < 3)) { PlayerPos = Player.GetComponent <Transform>().position; SelfPos = GetComponent <Transform>().position; Quaternion rotation = Quaternion.AngleAxis(PlayerDegree(), Vector3.forward); GameObject Bullet; Bullet = Instantiate(ShotPrefab, SelfPos, rotation); Bullet_behavior ShotVelocity = Bullet.GetComponent <Bullet_behavior>(); Damage_Script ShotDamage = Bullet.GetComponent <Damage_Script>(); Vector3 BulletVelocity = (PlayerPos - SelfPos); float RangeKey = Mathf.Sqrt(Mathf.Pow(BulletVelocity.x, 2) + Mathf.Pow(BulletVelocity.y, 2)) / 1; BulletVelocity = BulletVelocity / RangeKey * 20; ShotVelocity.Velocity = BulletVelocity; ShotDamage.HitDamage = 1; Shooting = 1; Shooted++; Invoke("ShootCool", 0.8f); } if (Shooted == 3) { Invoke("Reload", 2f); Shooted++; } }
void SpawnEnemy() { Vector3 PlayerPos = PlayerTransform.position; GameObject Enemy1; Enemy1 = Instantiate(Enemy1Prefab); Transform EnemyT = Enemy1.GetComponent <Transform>(); Enemy1_behavior EnemySet = Enemy1.GetComponent <Enemy1_behavior>(); Damage_Script Damage = Enemy1.GetComponent <Damage_Script>(); EnemyT.position = RocateEnemy(); EnemySet.Level = EnemyLevel; Damage.HitDamage = 1; }
void GetDamaged(Collider2D other) // Success { int Damage = 1; if (other.name != "Environment Damage") { Damage_Script Dmg = other.gameObject.GetComponent <Damage_Script>(); Damage = Dmg.HitDamage; } if (Invincible == 0) { if (Armor != 0) { Armor -= 1; Invincible = 1; //ArmorExplode(); Invoke("UnInvincible", 1f); } else if (HP != 0) { if (HP - Damage > 0) { HP -= Damage; Invincible = 1; Invoke("UnInvincible", 1f); } else { HP = 0; DEAD = 1; } } if (other.tag == "Enemy_Bullet") { Destroy(other.gameObject); } } }
void GunShot() // Success { Vector3 PlayerPos = PlayerTransform.position; float angle = Mathf.Atan2(MousePrivatePos.y - PlayerPos.y, MousePrivatePos.x - PlayerPos.x) * Mathf.Rad2Deg; Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward); GameObject Bullet; if ((Weapon != 2) && (Weapon != 4)) { Bullet = Instantiate(RoundShotPrefab, PlayerPos, rotation); } else { Bullet = Instantiate(LongShotPrefab, PlayerPos, rotation); } Bullet_behavior ShotVelocity = Bullet.GetComponent <Bullet_behavior>(); Damage_Script ShotDamage = Bullet.GetComponent <Damage_Script>(); ShotVelocity.Velocity = (MousePrivatePos - PlayerPos) * BulletSpeed[Weapon]; ShotDamage.HitDamage = WeaponDamage[Weapon]; if (Weapon == 3) { for (int i = 0; i <= 4; i++) { GameObject Bullets = Instantiate(RoundShotPrefab, PlayerPos, rotation); Bullet_behavior MoreShotVelocity = Bullets.GetComponent <Bullet_behavior>(); Damage_Script MoreShotDamage = Bullets.GetComponent <Damage_Script>(); MoreShotVelocity.Velocity = (MousePrivatePos - PlayerPos + new Vector3(Random.Range(-0.30f, 0.31f), Random.Range(-0.30f, 0.31f), 0)) * (BulletSpeed[Weapon] + Random.Range(-1.0f, 1.1f)); MoreShotDamage.HitDamage = WeaponDamage[Weapon]; } } }