using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public float Speed;
public float JumpForce;
bool isGrounded = false;
private Rigidbody2D rb;
float movX;
// Use this for initialization
void Start ()
{
rb = GetComponent<Rigidbody2D>();
}
void Update ()
{
movX = Input.GetAxis("Horizontal");
rb.velocity = new Vector2 (movX * Speed, rb.velocity.y);
if(Input.GetKeyDown(KeyCode.Space))
{
if(isGrounded)
jump ();
}
}
void jump()
{
rb.AddForce (transform.up * JumpForce);
isGrounded = false;
}
private void OnCollisioneEnter2D(Collision2D collision)
{
if(collision.gameObject.tag == "ground")
{
isGrounded = true;
}
}
}