Guest User

Untitled

a guest
Nov 20th, 2017
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Player : MonoBehaviour {
  6.  
  7. public float speed;
  8. public float jumpHeight;
  9. private bool jumping = false;
  10.  
  11. void OnCollisionEnter2D(Collision2D coll) {
  12. if (coll.gameObject.tag == "tempGround") {
  13. jumping = false;
  14. Debug.Log (jumping);
  15. }
  16. }
  17.  
  18. // Use this for initialization
  19. void Start () {
  20.  
  21. }
  22.  
  23. // Update is called once per frame
  24. void Update () {
  25. if (Input.GetAxisRaw("Horizontal") > 0.3f || Input.GetAxisRaw("Horizontal") < -0.3f) {
  26. transform.Translate (new Vector3(Input.GetAxisRaw("Horizontal") * speed * Time.deltaTime, 0f, 0f));
  27. }
  28. if (Input.GetKeyDown (KeyCode.Space) && jumping == false) {
  29. GetComponent<Rigidbody2D>().AddForce (Vector2.up * jumpHeight);
  30. jumping = true;
  31. }
  32. }
Add Comment
Please, Sign In to add comment