using UnityEngine;
using PicaVoxel;
using System.Collections.Generic;
public class RocketProjectile : MonoBehaviour {
public Rigidbody rocketProjectile;
private Exploder exploder;
private float speed = 30f;
private float life = 5f;
private float ExplosionRadius = 2f;
GameObject rocketPlayer;
private void Start()
{
exploder = gameObject.GetComponentInChildren<Exploder>();
rocketPlayer = GameObject.FindGameObjectWithTag("Player");
Invoke("DestroyMissile", life); //after 5 seconds destroy itself
}
void FireRocket()
{
transform.position += (transform.up * speed) * Time.deltaTime;
}
void Update()
{
FireRocket();
}
private void OnTriggerEnter(Collider other)
{
rocketProjectile.velocity = Vector3.zero;
// See if we can find a PicaVoxel Volume object on the thing we just collided with
var volume = other.GetComponentInParent<Volume>();
if (volume != null)
{
// We found a Volume, so explode!
var batch = volume.Explode(transform.position, ExplosionRadius, 0, Exploder.ExplodeValueFilterOperation.GreaterThanOrEqualTo);
if (batch.Voxels.Count > 0 && VoxelParticleSystem.Instance != null)
{
// Adjust these values to change the speed of the exploding particles
var minExplodeSpeed = 1f;
var maxExplodeSpeed = 2f;
VoxelParticleSystem.Instance.SpawnBatch(batch, pos => (pos - transform.position).normalized * Random.Range(minExplodeSpeed, maxExplodeSpeed));
}
}
Destroy(gameObject);
}
private void DestroyMissile()
{
exploder.Explode();
Destroy(gameObject);
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.