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.Experimental.Input;
- [RequireComponent(typeof(Rigidbody))]
- public class PlayerScript : MonoBehaviour
- {
- public int points = 0;
- public Vector3 jump;
- public float jumpForce = 5.0f;
- public bool isGrounded;
- Rigidbody rb;
- public GUIStyle customGUI;
- void Start()
- {
- rb = GetComponent<Rigidbody>();
- jump = new Vector3(0.0f, 5.0f, 0.0f);
- }
- void OnCollisionStay()
- {
- isGrounded = true;
- }
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
- {
- rb.AddForce(jump * jumpForce, ForceMode.Impulse);
- isGrounded = false;
- }
- }
- private void OnGUI()
- {
- GUI.Label(new Rect(20,20,150,20),"SCORE : " + points + "/50", customGUI);
- if (points >= 50)
- {
- GUI.Label(new Rect(700, 300, 150, 20), "YOU WIN!" , customGUI);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement