EnemyShooter.cs 1.2 KB

123456789101112131415161718192021222324252627282930
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class EnemyShooter : EnemyBase {
  5. internal override bool isPressingCrouch() => false;
  6. internal override bool isPressDownJump() => false;
  7. internal override bool isPressingLeft() => false;
  8. internal override bool isPressingRight() => false;
  9. internal override void OnHitEnemy(Collision2D collision) {}
  10. public float shootDelay = 5f, bulletSpeed = 1f; private float shootCooldown = 0f;
  11. public GameObject bullet;
  12. internal override void OnUpdate() {
  13. base.OnUpdate();
  14. if (!isLand) return;
  15. shootCooldown += Time.deltaTime;
  16. if (shootCooldown < shootDelay) return;
  17. // Éú³É×Óµ¯
  18. AudioM.Play("enemy_shoot", 0.3f);
  19. shootCooldown = shootDelay * ((float) Modules.randomDefault.NextDouble() * 0.4f - 0.2f);
  20. GameObject newBullet = Instantiate(bullet, transform);
  21. newBullet.transform.position += new Vector3(0.5f, -0.5f, 0);
  22. newBullet.transform.SetParent(null);
  23. newBullet.GetComponent<Rigidbody2D>().velocity = new Vector2((float) Modules.randomDefault.NextDouble() - 0.5f, 0.25f).normalized * bulletSpeed;
  24. }
  25. }