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 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]; } } }