Advertisement
Guest User

Untitled

a guest
Aug 8th, 2017
2,378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Projectile : MonoBehaviour {
  6.  
  7.     public float speed;
  8.     public Vector3 target;
  9.     public float lifeSpan;
  10.  
  11.     public GameObject dust;
  12.  
  13.     void Start () {
  14.         Vector3 targetRaiser = target;
  15.         targetRaiser.y = this.transform.position.y;
  16.         Vector3 relPos = targetRaiser - this.transform.position;
  17.         this.transform.rotation = Quaternion.LookRotation (relPos);
  18.         this.GetComponent<Rigidbody> ().AddForce (transform.forward * speed);
  19.         StartCoroutine (Life ());
  20.     }
  21.    
  22.  
  23.     void Update () {
  24.        
  25.     }
  26.  
  27.     void OnCollisionEnter(Collision obj){
  28.         if (obj.transform.tag == "ninja" || obj.transform.tag == "cowboy"){
  29.             GameObject.Find ("Manager").GetComponent<Manager> ().Sound (3);
  30.             Destroy (this.gameObject);
  31.         }
  32.         if (obj.transform.tag == "ground"){
  33.             Instantiate (dust, this.transform.position, this.transform.rotation);
  34.             GameObject.Find ("Manager").GetComponent<Manager> ().Sound (1);
  35.             Destroy (this.gameObject);
  36.         }
  37.  
  38.     }
  39.  
  40.     IEnumerator Life(){
  41.         yield return new WaitForSeconds (lifeSpan);
  42.         Destroy (this.gameObject);
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement