using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
public float speed;
public float jumpHeigth;
private Rigidbody2D rb;
RaycastHit hit;
Ray touchingGroundRay;
void Start () {
rb = GetComponent<Rigidbody2D> ();
touchingGroundRay = new Ray (transform.position, Vector3.down);
}
void Update () {
Debug.DrawRay (transform.position, Vector3.down * 1.5f);
if (Input.GetKeyDown (KeyCode.Space) && Physics.Raycast (touchingGroundRay,out hit, 1.5f)) {
rb.velocity = new Vector2 (rb.velocity.x, jumpHeigth);
}
if(Input.GetKey(KeyCode.D)) {
rb.velocity = new Vector2 (speed, rb.velocity.y);
}
if(Input.GetKey(KeyCode.A)) {
rb.velocity = new Vector2 (-speed, rb.velocity.y);
}
}
}