Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //JM
- public class PlayerController : MonoBehaviour {
- public int health;
- public float speed;
- public float sensitivity;
- float mouse;
- float horiz;
- float vert;
- Rigidbody rig;
- public List<GameObject> weapons = new List<GameObject>();
- public GameObject currentWeapon;
- public GameObject pistolShotSpawn;
- public GameObject rifleShotSpawn;
- public GameObject launcherShotSpawn;
- public int weapon;
- public GameObject friendly;
- public GameObject pistolShot;
- public GameObject launcherShot;
- public GameObject rifleShot;
- void Start () {
- rig = this.GetComponent<Rigidbody>();
- currentWeapon = weapons[0];
- weapon = 0;
- }
- void Update () {
- vert = Input.GetAxis("Vertical");
- horiz = Input.GetAxis("Horizontal");
- mouse = Input.GetAxis("Mouse X");
- if(Input.GetKeyDown(KeyCode.E))
- {
- weapon++;
- currentWeapon.SetActive(false);
- if (weapon > weapons.Count-1)
- weapon = 0;
- currentWeapon = weapons[weapon];
- currentWeapon.SetActive(true);
- }
- if(Input.GetKeyDown(KeyCode.Q))
- {
- weapon--;
- currentWeapon.SetActive(false);
- if (weapon < 0)
- weapon = weapons.Count-1;
- currentWeapon = weapons[weapon];
- currentWeapon.SetActive(true);
- }
- if (health <= 0)
- Destroy(this.gameObject);
- }
- private void FixedUpdate()
- {
- Move();
- Shoot();
- if(Input.GetKeyDown(KeyCode.C))
- transform.rotation = new Quaternion(0, transform.rotation.y, 0, 0);
- }
- private void Move()
- {
- rig.MovePosition(transform.position + (transform.forward * vert * speed) + (transform.right * horiz * speed));
- rig.MoveRotation(rig.rotation * Quaternion.Euler(new Vector3(0, mouse * sensitivity, 0)));
- }
- private void Shoot()
- {
- if (Input.GetKeyDown(KeyCode.Space))
- {
- if (weapons[weapon].name == "Pistol")
- {
- Instantiate(pistolShot, pistolShotSpawn.transform.position, pistolShotSpawn.transform.rotation);
- }
- if (weapons[weapon].name == "Launcher")
- {
- Instantiate(launcherShot, launcherShotSpawn.transform.position, launcherShotSpawn.transform.rotation);
- }
- if (weapons[weapon].name == "Rifle")
- {
- Instantiate(rifleShot, rifleShotSpawn.transform.position, rifleShotSpawn.transform.rotation);
- }
- }
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.CompareTag("Enemy") && other.isTrigger == false)
- {
- Debug.Log("triggerenter" + other.name);
- friendly.GetComponent<FriendlyScript>().enemySpotted = true;
- friendly.GetComponent<FriendlyScript>().spottedEnemy = other.gameObject;
- if(other.name == "Enemy1")
- other.GetComponent<Enemy1>().playerClose = true;
- }
- }
- private void OnTriggerExit(Collider other)
- {
- if (other.CompareTag("Enemy") && other.isTrigger == false)
- {
- friendly.GetComponent<FriendlyScript>().enemySpotted = false;
- friendly.GetComponent<FriendlyScript>().spottedEnemy = null;
- other.GetComponent<Enemy1>().playerClose = false;
- }
- }
- }
- public class ProjectileScript : MonoBehaviour {
- public int damage;
- public float speed;
- private void Start()
- {
- gameObject.GetComponent<Rigidbody>().velocity = gameObject.transform.forward * speed;
- }
- private void Update()
- {
- Destroy(this.gameObject, 5.0f);
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.isTrigger != true)
- {
- if (other.CompareTag("Enemy"))
- {
- other.GetComponent<EnemyBase>().health -= damage;
- }
- if (other.CompareTag("Friendly"))
- {
- other.GetComponent<FriendlyScript>().health -= damage;
- }
- if (other.CompareTag("Player"))
- {
- other.GetComponent<PlayerController>().health -= damage;
- }
- Destroy(this.gameObject);
- }
- }
- }
- public class HealthPickup : MonoBehaviour {
- public int healthBonus;
- private void OnTriggerEnter(Collider other)
- {
- if (other.CompareTag("Player") && other.isTrigger == false)
- {
- other.GetComponent<PlayerController>().health += healthBonus;
- Destroy(this.gameObject);
- }
- }
- }
- public class EnemyBase : MonoBehaviour{
- public NavMeshAgent agent;
- public int health;
- public GameObject player;
- public void Death()
- {
- if(health<=0)
- Destroy(this.gameObject);
- }
- }
- public class Enemy1 : EnemyBase {
- public bool inRadius = false;
- public bool playerClose = false;
- public GameObject bullet;
- public Transform shotSpawn;
- public float lastShot;
- public float fireRate;
- private void Start()
- {
- agent = GetComponent<NavMeshAgent>();
- }
- private void FixedUpdate()
- {
- if (inRadius == true && playerClose == false)
- {
- agent.isStopped = false;
- agent.destination = player.transform.position;
- }
- if (playerClose)
- {
- transform.LookAt(player.transform.position);
- }
- }
- private void Update()
- {
- if(playerClose)
- {
- if (Time.realtimeSinceStartup - fireRate > lastShot)
- {
- Shoot();
- lastShot = Time.realtimeSinceStartup;
- }
- }
- Death();
- }
- private void OnTriggerEnter(Collider other)
- {
- if(other.CompareTag("Player") && other.isTrigger == false)
- {
- inRadius = true;
- }
- }
- private void OnTriggerExit(Collider other)
- {
- if (other.CompareTag("Player") && other.isTrigger == false)
- {
- inRadius = false;
- }
- }
- private void Shoot()
- {
- Instantiate(bullet, shotSpawn.transform.position, shotSpawn.transform.rotation);
- }
- }
- public class Enemy2 : EnemyBase {
- public List<GameObject> waypoints = new List<GameObject>();
- public int waypoint;
- public bool chasingPlayer = false;
- private void Start()
- {
- agent = GetComponent<NavMeshAgent>();
- agent.destination = waypoints[0].transform.position;
- waypoint = 1;
- }
- private void Update()
- {
- if (chasingPlayer)
- {
- agent.destination = player.transform.position;
- }
- else
- {
- agent.destination = waypoints[waypoint].transform.position;
- }
- if(waypoint > waypoints.Count-1)
- {
- waypoint = 0;
- }
- Death();
- }
- private void OnTriggerEnter(Collider other)
- {
- if(other.gameObject == player && other.isTrigger == false)
- {
- chasingPlayer = true;
- }
- }
- private void OnTriggerExit(Collider other)
- {
- if (other.gameObject == player && other.isTrigger == false)
- chasingPlayer = false;
- }
- private void OnCollisionEnter(Collision collision)
- {
- if(collision.gameObject.CompareTag("Waypoint") && collision.collider.isTrigger == true)
- {
- Debug.Log("HELLO?!");
- waypoint++;
- }
- }
- }
- public class Sword : MonoBehaviour {
- public int damage;
- private void OnTriggerExit(Collider other)
- {
- if(other.CompareTag("Player") && other.isTrigger == false)
- {
- other.GetComponent<PlayerController>().health -= damage;
- }
- }
- }
- public class CamerScript : MonoBehaviour {
- public GameObject player;
- void Update () {
- transform.position = new Vector3(player.transform.position.x, player.transform.position.y + 0.73f, player.transform.position.z);
- transform.rotation = player.transform.rotation;
- }
- }
- public class Waypoint : MonoBehaviour {
- public GameObject enemy2;
- private void OnTriggerEnter(Collider other)
- {
- Debug.Log("trigger" + other.name);
- if(other.gameObject == enemy2 && other.isTrigger == false)
- {
- other.gameObject.GetComponent<Enemy2>().waypoint++;
- Debug.Log("waypoint++");
- }
- }
- }
- public class WeaponPickup : MonoBehaviour {
- public GameObject weapon;
- private void OnTriggerEnter(Collider other)
- {
- if(other.gameObject.CompareTag("Player") && other.isTrigger == false)
- {
- other.GetComponent<PlayerController>().weapons.Add(weapon);
- Destroy(this.gameObject);
- }
- }
- }
- public class FriendlyScript : MonoBehaviour {
- public GameObject player;
- public bool enemySpotted;
- public int health;
- public GameObject spottedEnemy;
- NavMeshAgent agent;
- public float fireRate;
- public Transform shotSpawn;
- public GameObject bullet;
- public float lastShot;
- private void Start()
- {
- agent = GetComponent<NavMeshAgent>();
- agent.destination = player.transform.position;
- }
- private void Update()
- {
- if (health <= 0)
- Destroy(this.gameObject);
- if (enemySpotted == true && spottedEnemy == null)
- enemySpotted = false;
- }
- private void FixedUpdate()
- {
- if (enemySpotted == false)
- {
- agent.destination = player.transform.position;
- agent.isStopped = false;
- }
- else if (enemySpotted == true)
- {
- agent.isStopped = true;
- transform.LookAt(spottedEnemy.transform.position);
- if (Time.realtimeSinceStartup - fireRate > lastShot)
- {
- Shoot();
- lastShot = Time.realtimeSinceStartup;
- }
- }
- }
- private void Shoot()
- {
- Instantiate(bullet, shotSpawn.transform.position, shotSpawn.transform.rotation);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement