add: rocket launcher scripts
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class RocketLauncher : Weapon
|
||||
{
|
||||
public GameObject projectilePrefab;
|
||||
public Transform spawnPosition;
|
||||
public float fireRate = 0.3f;
|
||||
|
||||
[SerializeField] float currentDelay = 0;
|
||||
|
||||
public override void Shoot(bool keyDown, bool keyHold) {
|
||||
if (keyHold && (fireRate == 0 || currentDelay >= 1 / fireRate) && GameController.i.ConsumeBullet(bulletType)) {
|
||||
Instantiate(projectilePrefab, spawnPosition.position, spawnPosition.rotation);
|
||||
currentDelay = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Update() {
|
||||
if (fireRate != 0) currentDelay = Mathf.Clamp(currentDelay += Time.deltaTime, 0, 1 / fireRate);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: adc348041e3fec6468a64ec626053bc3
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b620769c55dfa849b7fd23858b7cc1f
|
||||
Reference in New Issue
Block a user