Files
WildRoot/Assets/Script/Bullet.cs
T

51 lines
1.2 KiB
C#
Raw Normal View History

2026-04-14 17:06:58 +09:00
using UnityEngine;
public class Bullet : MonoBehaviour
{
public float speed = 8f;
private Rigidbody rb;
public GameObject effect;
2026-04-29 09:22:08 +09:00
public bool isPlayerBullet = false;
void Start()
{
rb = GetComponent<Rigidbody>();
rb.linearVelocity = transform.forward * speed;
Destroy(gameObject, 3f);
}
2026-04-14 17:06:58 +09:00
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Shield"))
{
return;
}
if (other.CompareTag("Player"))
{
2026-04-29 09:22:08 +09:00
if (!isPlayerBullet)
2026-04-14 17:06:58 +09:00
{
2026-04-29 09:22:08 +09:00
Instantiate(effect, other.transform.position, Quaternion.identity);
PlayerController pc = other.GetComponent<PlayerController>();
if (pc != null)
{
pc.Die();
GameManager.instance.PlayDeathMusic();
}
Destroy(gameObject);
2026-04-14 17:06:58 +09:00
}
2026-04-29 09:22:08 +09:00
return;
2026-04-14 17:06:58 +09:00
}
2026-04-29 09:22:08 +09:00
if (other.CompareTag("Spawner"))
{
if (isPlayerBullet)
{
Destroy(other.gameObject);
Destroy(gameObject);
}
return;
}
2026-04-14 17:06:58 +09:00
}
2026-04-29 09:22:08 +09:00
}