using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public Vector3 direction; //x y z
public float Speed = 10; //213.4324235
public float Gravity = -10;
public float JumpSpeed = 10;
public CharacterController controller; //
public Transform grondCheck;
public LayerMask groundLayer;
bool isGrounded = true;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float hInput = Input.GetAxis("Horizontal");
direction.x = hInput*Speed;
// direction.y += Gravity*Time.deltaTime;
isGrounded = Physics.CheckSphere(grondCheck.position, 0.2f, groundLayer);
if(isGrounded)
{
if (Input.GetButtonDown("Jump"))
{
direction.y = -1;
direction.y = JumpSpeed;
Debug.Log("Jump");
}
}
else
{
direction.y += Gravity * Time.deltaTime;
}
controller.Move(direction * Time.deltaTime);
}
}