Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.AI;
- public class Cowboy : MonoBehaviour {
- public NavMeshAgent nav;
- Vector3 newpos;
- public GameObject spawner;
- public GameObject projectile;
- public GameObject blood;
- void Start () {
- newpos = this.transform.position;
- }
- void Update () {
- if (nav.destination != newpos){
- nav.destination = newpos;
- }
- bool RMB = Input.GetMouseButton (1);
- bool LMB = Input.GetMouseButtonDown (0);
- if (RMB){
- RaycastHit hit;
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- if (Physics.Raycast(ray, out hit)){
- string tag = hit.transform.tag;
- switch(tag){
- case "ground":
- Move (hit.point);
- break;
- }
- }
- }
- if (LMB){
- RaycastHit hit;
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- if (Physics.Raycast(ray, out hit) && hit.transform.tag != "cowboy" && hit.transform.tag != "button"){
- Shoot (hit.point);
- }
- }
- }
- void OnCollisionEnter(Collision obj){
- if (obj.transform.tag == "star"){
- Death ();
- }
- }
- void Death(){
- Instantiate (blood, this.transform.position, this.transform.rotation);
- GameObject.Find ("Manager").GetComponent<Manager> ().Sound (2);
- Destroy (this.gameObject);
- }
- void Shoot(Vector3 dir){
- GameObject.Find ("Manager").GetComponent<Manager> ().Sound (0);
- Move (this.transform.position);
- Vector3 relPos = dir - this.transform.position;
- this.transform.rotation = Quaternion.LookRotation (relPos);
- GameObject star = Instantiate (projectile, spawner.transform.position, spawner.transform.rotation);
- star.GetComponent<Projectile>().target = dir;
- }
- void Move(Vector3 pos){
- newpos = pos;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement