53 lines
1.0 KiB
C#
53 lines
1.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEditor.Experimental.GraphView;
|
|
using UnityEngine;
|
|
using UnityEngine.TextCore.Text;
|
|
|
|
public class Player : MonoBehaviour
|
|
{
|
|
private CharacterController character;
|
|
private Vector3 direction;
|
|
|
|
public float gravity = 9.81f * 2f;
|
|
|
|
public float jumpForce = 8f;
|
|
|
|
private void Awake()
|
|
{
|
|
character = GetComponent<CharacterController>();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
direction = Vector3.zero;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
direction += Vector3.down * gravity * Time.deltaTime;
|
|
|
|
if (character.isGrounded)
|
|
{
|
|
direction = Vector3.down;
|
|
|
|
if (Input.GetButton("Jump"))
|
|
{
|
|
|
|
direction = Vector3.up * jumpForce;
|
|
}
|
|
}
|
|
|
|
character.Move(direction * Time.deltaTime);
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.CompareTag("Obstacle"))
|
|
{
|
|
GameManager.Instance.GameOver();
|
|
}
|
|
}
|
|
|
|
}
|