g1/Assets/Bullet.cs

32 lines
707 B
C#
Raw Normal View History

2026-01-26 11:59:13 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullet : MonoBehaviour
{
public float speed = 8f;
private Rigidbody bulletRigidbody;
void Start()
{
bulletRigidbody = GetComponent<Rigidbody>();
bulletRigidbody.linearVelocity = transform.forward * speed;
Destroy(gameObject, 3f);
}
void OnTriggerEnter(Collider other)
{
if(other.tag == "Player")
{
PlayerController playerController = other.GetComponent<PlayerController>();
if(playerController != null )
{
playerController.Die();
}
}
}
void Update()
{
}
}