Files
No-Time-To-Rest/Assets/Scripts/BulletProjectile.cs
T
2025-03-08 22:41:34 +03:00

31 lines
691 B
C#

using UnityEngine;
public class BulletProjectile : MonoBehaviour
{
public float speed = 1f;
public float damage = 20f;
public float timeToLive = 5f;
float currentTime = 0;
Rigidbody rb;
void Start() {
rb = GetComponent<Rigidbody>();
rb.linearVelocity = transform.forward * speed;
}
void Update() {
currentTime += Time.deltaTime;
if (currentTime >= timeToLive) Destroy(gameObject);
}
void OnTriggerEnter(Collider other) {
if (other.gameObject.CompareTag("Enemy")) {
Enemy enemy = other.GetComponent<Enemy>();
enemy.DealDamage(damage);
}
Destroy(gameObject);
}
}