2026-05-09 09:00:14 +07:00
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
|
|
|
|
|
|
public class BluePlayerController : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public GameObject shield;
|
|
|
|
|
|
|
|
|
|
public GameObject bulletPrefab;
|
|
|
|
|
public Transform firePoint;
|
|
|
|
|
|
|
|
|
|
public float shootCooldown = 0.5f;
|
|
|
|
|
|
|
|
|
|
private float cooldownTimer;
|
|
|
|
|
|
|
|
|
|
private bool isDead = false;
|
2026-05-12 10:08:40 +07:00
|
|
|
public AudioSource audioSource;
|
|
|
|
|
public AudioClip audioClip;
|
2026-05-09 09:00:14 +07:00
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
if (Keyboard.current == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (isDead)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
cooldownTimer -= Time.deltaTime;
|
|
|
|
|
|
|
|
|
|
HandleShield();
|
|
|
|
|
HandleShoot();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HandleShield()
|
|
|
|
|
{
|
|
|
|
|
// Giữ F => bỏ khiên
|
|
|
|
|
bool holdingF =
|
|
|
|
|
Keyboard.current.fKey.isPressed;
|
|
|
|
|
|
|
|
|
|
shield.SetActive(!holdingF);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HandleShoot()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Chỉ bắn khi đang bỏ khiên
|
|
|
|
|
if (!shield.activeSelf &&
|
|
|
|
|
Keyboard.current.gKey.wasPressedThisFrame &&
|
|
|
|
|
cooldownTimer <= 0f)
|
|
|
|
|
{
|
2026-05-12 10:08:40 +07:00
|
|
|
AudioSource.PlayClipAtPoint(audioClip, firePoint.position);
|
2026-05-09 09:00:14 +07:00
|
|
|
Instantiate(
|
|
|
|
|
bulletPrefab,
|
|
|
|
|
firePoint.position,
|
|
|
|
|
firePoint.rotation
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
cooldownTimer = shootCooldown;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Die()
|
|
|
|
|
{
|
|
|
|
|
isDead = true;
|
|
|
|
|
|
|
|
|
|
GameManager.Instance.ShowWinner("RED WIN!");
|
|
|
|
|
}
|
|
|
|
|
}
|