Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Player : MonoBehaviour {
- public float speed;
- public float jumpHeight;
- private bool jumping = false;
- void OnCollisionEnter2D(Collision2D coll) {
- if (coll.gameObject.tag == "tempGround") {
- jumping = false;
- Debug.Log (jumping);
- }
- }
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- if (Input.GetAxisRaw("Horizontal") > 0.3f || Input.GetAxisRaw("Horizontal") < -0.3f) {
- transform.Translate (new Vector3(Input.GetAxisRaw("Horizontal") * speed * Time.deltaTime, 0f, 0f));
- }
- if (Input.GetKeyDown (KeyCode.Space) && jumping == false) {
- GetComponent<Rigidbody2D>().AddForce (Vector2.up * jumpHeight);
- jumping = true;
- }
- }
Add Comment
Please, Sign In to add comment