Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class TorpedoController : MonoBehaviour {
- public float moveSpeed = 15;
- public float selfDestruct = 400;
- private float movedDistance = 0;
- public GameObject explosionPrefab;
- // Update is called once per frame
- void Update () {
- transform.position = transform.position + (transform.forward * moveSpeed * Time.deltaTime);
- movedDistance += moveSpeed * Time.deltaTime;
- if (movedDistance > selfDestruct) {
- Destroy (gameObject);
- }
- }
- void OnTriggerEnter(Collider other) {
- if (other.gameObject.tag == "Enemy") {
- Destroy (other.gameObject);
- Explode ();
- }
- if (other.gameObject.tag == "Ground") {
- Explode ();
- }
- }
- void Explode() {
- GameObject.Instantiate (explosionPrefab, transform.position, transform.rotation);
- Destroy (gameObject);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement