add: pistol weapon and enemy

This commit is contained in:
KOSMOGOR
2025-03-08 22:41:34 +03:00
parent 7d6cef4989
commit 17f3448f6c
14 changed files with 542 additions and 3 deletions
+30
View File
@@ -0,0 +1,30 @@
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);
}
}