EnemyShooter.cs 1.1 KB

1234567891011121314151617181920212223242526272829
  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. if (!isLand) return;
  14. shootCooldown += Time.deltaTime;
  15. if (shootCooldown < shootDelay) return;
  16. shootCooldown = 0f;
  17. // TODO: ¹¥»÷ÒôЧ
  18. // Éú³É×Óµ¯
  19. GameObject newBullet = Instantiate(bullet, transform);
  20. newBullet.transform.position += new Vector3(0.5f, -0.5f, 0);
  21. newBullet.transform.SetParent(null);
  22. newBullet.GetComponent<Rigidbody2D>().velocity = new Vector2((float) Modules.randomDefault.NextDouble() - 0.5f, 0.25f).normalized * bulletSpeed;
  23. }
  24. }