Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //JM
- public class PlayerController : MonoBehaviour {
- public float speed;
- public float sensitivity;
- public Slider healthBar;
- public int health;
- private Rigidbody rig;
- public bool controlType;
- float mouse;
- float horiz;
- float vert;
- public Transform shotSpawn;
- public GameObject bullet;
- // Use this for initialization
- void Start () {
- rig = GetComponent<Rigidbody>();
- controlType = false;
- health = 100;
- }
- // Update is called once per frame
- void Update () {
- healthBar.value = health;
- if (controlType == false)
- {
- vert = Input.GetAxis("Vertical");
- horiz = Input.GetAxis("Horizontal");
- mouse = Input.GetAxis("Mouse X");
- }
- else
- {
- vert = Input.GetAxis("Vertical2");
- horiz = Input.GetAxis("Horizontal2");
- mouse = Input.GetAxis("Mouse X2");
- }
- Vector3 whereToSpawn = new Vector3(shotSpawn.position.x, shotSpawn.position.y, shotSpawn.position.z);
- Quaternion direction = new Quaternion(shotSpawn.rotation.x, shotSpawn.rotation.y, shotSpawn.rotation.z, shotSpawn.rotation.w);
- if (health <= 0)
- Destroy(this);
- if (Input.GetKeyDown(KeyCode.Space))
- Instantiate(bullet, whereToSpawn,direction);
- if (Input.GetKeyDown(KeyCode.V) && controlType == false)
- controlType = true;
- else if (Input.GetKeyDown(KeyCode.V))
- controlType = false;
- }
- private void FixedUpdate()
- {
- rig.MovePosition(transform.position+ (transform.forward * vert * speed) + (transform.right * horiz * speed));
- rig.MoveRotation(rig.rotation * Quaternion.Euler(new Vector3(0, mouse * sensitivity, 0)));
- if (Input.GetKeyDown(KeyCode.C))
- {
- transform.rotation = new Quaternion(0, transform.rotation.y, 0, 0);
- transform.position = new Vector3(transform.position.x, 1, transform.position.z);
- }
- }
- }
- public class Enemy : MonoBehaviour {
- public int health;
- public Slider healthBar;
- public GameObject justhit;
- private void Start()
- {
- health = 100;
- }
- private void Update()
- {
- healthBar.value = health;
- if (health <= 0)
- Destroy(this.gameObject);
- }
- }
- public class Bullet : MonoBehaviour {
- public float speed;
- public GameObject shot;
- private Stopwatch sw;
- // Use this for initialization
- void Start () {
- sw = new Stopwatch();
- sw.Start();
- }
- // Update is called once per frame
- void Update () {
- if (sw.ElapsedMilliseconds >= 10000)
- Destroy(this.gameObject);
- }
- private void FixedUpdate()
- {
- transform.Translate(new Vector3(0, speed, 0));
- }
- private void OnTriggerEnter(Collider other)
- {
- shot = other.gameObject;
- if(shot.CompareTag("Enemy"))
- {
- shot.GetComponent<Enemy>().health -= 10;
- }
- Destroy(this.gameObject);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement