EnemyShooter.cs 1.1 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. shootCooldown = 0f;
  18. // TODO: 攻击音效(来不及可以不要了……)
  19. // 生成子弹
  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. }