Advertisement
Guest User

Untitled

a guest
Apr 18th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerControll : MonoBehaviour {
  5.  
  6. public bool isGrounded;
  7. public float jumpHeight = 5F;
  8. public float speed = 0.1F;
  9. private Vector3 spawn;
  10. public GameObject deathParticles;
  11. public bool standardPlayer;
  12. public Material[] materials;
  13.  
  14. private BoxCollider BC;
  15. private Rigidbody rb;
  16.  
  17. void Start (){
  18. standardPlayer = true;
  19. spawn = transform.position;
  20. rb = this.gameObject.GetComponent<Rigidbody>();
  21. // Checks if there is a rigidbody component
  22. if (rb == null) {
  23. Debug.Log ("this gameobject" + this.gameObject.name + "dose not contain a rigidbody");
  24. return;
  25. }
  26. }
  27.  
  28.  
  29. void OnCollisionEnter (Collision other) {
  30. isGrounded = true;
  31. if (other.transform.tag == "Enemy") {
  32. Instantiate (deathParticles, transform.position, Quaternion.identity);
  33. transform.position = spawn;
  34. }
  35. if (other.transform.tag == "Poison" && standardPlayer == true){
  36. Instantiate(deathParticles, transform.position, Quaternion.identity);
  37. transform.position = spawn;
  38. }
  39. }
  40.  
  41.  
  42. void FixedUpdate (){
  43. // Moves the player horizontally
  44. rb.position += new Vector3 (Input.GetAxis ("Horizontal") * speed, 0, 0);
  45. // Check and jump
  46. if (Input.GetKeyDown (KeyCode.UpArrow) || Input.GetKeyDown (KeyCode.W) || Input.GetKeyDown (KeyCode.Space)) {
  47. if (isGrounded == true) {
  48. rb.velocity = new Vector3 (0, jumpHeight, 0);
  49. isGrounded = false;
  50. }
  51. }
  52. if (standardPlayer == true) {
  53. if (Input.GetKeyDown(KeyCode.Q)){
  54. standardPlayer = false;
  55. Renderer rend = GetComponent<Renderer>(); rend.material = materials[1];
  56. }
  57. }
  58. if (standardPlayer == false) {
  59. if (Input.GetKeyDown (KeyCode.Q)) {
  60. standardPlayer = true;
  61. Renderer rend = GetComponent<Renderer> (); rend.material = materials[0];
  62. }
  63. }
  64. }
  65.  
  66. void update () {
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement