add: rocket launcher scripts

This commit is contained in:
KOSMOGOR
2025-04-30 21:23:38 +03:00
parent 85dc2955cf
commit a5b234974e
4 changed files with 59 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
using UnityEngine;
public class RocketProjectile : MonoBehaviour
{
public float speed = 1f;
public float damage = 50f;
public float explosionRadius = 5f;
public float timeToLive = 3f;
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) {
Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius);
foreach (Collider collider in colliders) {
if (collider.gameObject.CompareTag("Enemy")) {
Enemy enemy = other.GetComponent<Enemy>();
enemy.DealDamage(damage);
}
}
Destroy(gameObject);
}
}