SHARE
TWEET

Untitled

a guest Aug 8th, 2017 6,633 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.AI;
  5.  
  6. public class Cowboy : MonoBehaviour {
  7.  
  8.     public NavMeshAgent nav;
  9.     Vector3 newpos;
  10.     public GameObject spawner;
  11.  
  12.     public GameObject projectile;
  13.     public GameObject blood;
  14.  
  15.     void Start () {
  16.         newpos = this.transform.position;
  17.     }
  18.    
  19.  
  20.     void Update () {
  21.         if (nav.destination != newpos){
  22.             nav.destination = newpos;
  23.         }
  24.  
  25.         bool RMB = Input.GetMouseButton (1);
  26.         bool LMB = Input.GetMouseButtonDown (0);
  27.  
  28.         if (RMB){
  29.  
  30.             RaycastHit hit;
  31.             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  32.  
  33.             if (Physics.Raycast(ray, out hit)){
  34.                 string tag = hit.transform.tag;
  35.                 switch(tag){
  36.                 case "ground":
  37.                     Move (hit.point);
  38.                     break;
  39.                 }
  40.  
  41.             }
  42.  
  43.         }
  44.  
  45.         if (LMB){
  46.             RaycastHit hit;
  47.             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  48.  
  49.             if (Physics.Raycast(ray, out hit) && hit.transform.tag != "cowboy" && hit.transform.tag != "button"){
  50.                 Shoot (hit.point);
  51.             }
  52.         }
  53.     }
  54.  
  55.     void OnCollisionEnter(Collision obj){
  56.         if (obj.transform.tag == "star"){
  57.             Death ();
  58.         }
  59.  
  60.     }
  61.  
  62.     void Death(){
  63.         Instantiate (blood, this.transform.position, this.transform.rotation);
  64.         GameObject.Find ("Manager").GetComponent<Manager> ().Sound (2);
  65.         Destroy (this.gameObject);
  66.     }
  67.     void Shoot(Vector3 dir){
  68.         GameObject.Find ("Manager").GetComponent<Manager> ().Sound (0);
  69.         Move (this.transform.position);
  70.         Vector3 relPos = dir - this.transform.position;
  71.         this.transform.rotation = Quaternion.LookRotation (relPos);
  72.         GameObject star = Instantiate (projectile, spawner.transform.position, spawner.transform.rotation);
  73.         star.GetComponent<Projectile>().target = dir;
  74.     }
  75.     void Move(Vector3 pos){
  76.         newpos = pos;
  77.     }
  78. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top