This commit is contained in:
manhduyhoang90
2026-05-09 09:00:14 +07:00
parent 48fa714dec
commit 4fc787e83f
50 changed files with 4057 additions and 7 deletions

View File

@@ -0,0 +1,65 @@
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;
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)
{
Instantiate(
bulletPrefab,
firePoint.position,
firePoint.rotation
);
cooldownTimer = shootCooldown;
}
}
public void Die()
{
isDead = true;
GameManager.Instance.ShowWinner("RED WIN!");
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 16ca7876af4ace2468e2289a8513ae82

45
Assets/Scripts/Bullet.cs Normal file
View File

@@ -0,0 +1,45 @@
using UnityEngine;
public class Bullet : MonoBehaviour
{
public float speed = 10f;
void Update()
{
transform.position += transform.forward * speed * Time.deltaTime;
}
private void OnTriggerEnter(Collider other)
{
// Trúng khiên
if (other.CompareTag("Shield"))
{
Destroy(gameObject);
return;
}
// Trúng đầu
if (other.CompareTag("BluePlayer"))
{
HitBox hit = other.GetComponent<HitBox>();
if (hit != null)
{
hit.blueplayer.Die();
}
Destroy(gameObject);
}
if (other.CompareTag("RedPlayer"))
{
HitBox hit = other.GetComponent<HitBox>();
if (hit != null)
{
hit.redplayer.Die();
}
Destroy(gameObject);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b3d0c723e563624469ed05366a4184d3

View File

@@ -0,0 +1,35 @@
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
public static GameManager Instance;
public GameObject resultPanel;
public TextMeshProUGUI resultText;
private void Awake()
{
Instance = this;
}
public void ShowWinner(string loserName)
{
resultPanel.SetActive(true);
if (loserName.Contains("Blue"))
resultText.text = "RED WIN!";
else
resultText.text = "BLUE WIN!";
Time.timeScale = 0f;
}
public void Again()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
Time.timeScale = 1f;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 61e65f88b41b87a4cb5404645938e821

7
Assets/Scripts/HitBox.cs Normal file
View File

@@ -0,0 +1,7 @@
using UnityEngine;
public class HitBox : MonoBehaviour
{
public BluePlayerController blueplayer;
public RedPlayerController redplayer;
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d3c9212d3857e5b4893a36729d359906

View File

@@ -0,0 +1,65 @@
using UnityEngine;
using UnityEngine.InputSystem;
public class RedPlayerController : MonoBehaviour
{
public GameObject shield;
public GameObject bulletPrefab;
public Transform firePoint;
public float shootCooldown = 0.5f;
private float cooldownTimer;
private bool isDead = false;
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.kKey.isPressed;
shield.SetActive(!holdingF);
}
void HandleShoot()
{
// Chỉ bắn khi đang bỏ khiên
if (!shield.activeSelf &&
Keyboard.current.jKey.wasPressedThisFrame &&
cooldownTimer <= 0f)
{
Instantiate(
bulletPrefab,
firePoint.position,
firePoint.rotation
);
cooldownTimer = shootCooldown;
}
}
public void Die()
{
isDead = true;
GameManager.Instance.ShowWinner("BLUE WIN!");
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e10bf968efdc6624a85b1b79a5806946