Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Projectile : MonoBehaviour {
- public float speed;
- public Vector3 target;
- public float lifeSpan;
- public GameObject dust;
- void Start () {
- Vector3 targetRaiser = target;
- targetRaiser.y = this.transform.position.y;
- Vector3 relPos = targetRaiser - this.transform.position;
- this.transform.rotation = Quaternion.LookRotation (relPos);
- this.GetComponent<Rigidbody> ().AddForce (transform.forward * speed);
- StartCoroutine (Life ());
- }
- void Update () {
- }
- void OnCollisionEnter(Collision obj){
- if (obj.transform.tag == "ninja" || obj.transform.tag == "cowboy"){
- GameObject.Find ("Manager").GetComponent<Manager> ().Sound (3);
- Destroy (this.gameObject);
- }
- if (obj.transform.tag == "ground"){
- Instantiate (dust, this.transform.position, this.transform.rotation);
- GameObject.Find ("Manager").GetComponent<Manager> ().Sound (1);
- Destroy (this.gameObject);
- }
- }
- IEnumerator Life(){
- yield return new WaitForSeconds (lifeSpan);
- Destroy (this.gameObject);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement