RocketProjectile.cs

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 = 5.0f; GameObject rocketPlayer; private void Start() { exploder = gameObject.GetComponentInChildren<Exploder>(); rocketPlayer = GameObject.FindGameObjectWithTag("Player"); Invoke("DetonateMissile", 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; DetonateMissile(); } void DetonateMissile() { 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.