.
This commit is contained in:
45
Assets/Scripts/Bullet.cs
Normal file
45
Assets/Scripts/Bullet.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user