Advertisement
dianamrazova

Unity Player Script

Dec 11th, 2019
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Experimental.Input;
  5. [RequireComponent(typeof(Rigidbody))]
  6.  
  7.  
  8. public class PlayerScript : MonoBehaviour
  9. {
  10. public int points = 0;
  11.  
  12.  
  13. public Vector3 jump;
  14. public float jumpForce = 5.0f;
  15.  
  16.  
  17. public bool isGrounded;
  18. Rigidbody rb;
  19.  
  20. public GUIStyle customGUI;
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27. void Start()
  28. {
  29. rb = GetComponent<Rigidbody>();
  30. jump = new Vector3(0.0f, 5.0f, 0.0f);
  31.  
  32.  
  33. }
  34.  
  35. void OnCollisionStay()
  36. {
  37. isGrounded = true;
  38. }
  39.  
  40.  
  41.  
  42.  
  43. void Update()
  44. {
  45. if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
  46. {
  47.  
  48. rb.AddForce(jump * jumpForce, ForceMode.Impulse);
  49. isGrounded = false;
  50. }
  51. }
  52. private void OnGUI()
  53. {
  54.  
  55. GUI.Label(new Rect(20,20,150,20),"SCORE : " + points + "/50", customGUI);
  56.  
  57. if (points >= 50)
  58. {
  59. GUI.Label(new Rect(700, 300, 150, 20), "YOU WIN!" , customGUI);
  60. }
  61.  
  62.  
  63.  
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement