Skip to content

Instantly share code, notes, and snippets.

@kazumalab
Created March 28, 2017 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazumalab/3c5a2122509eb777f71b2097b9560498 to your computer and use it in GitHub Desktop.
Save kazumalab/3c5a2122509eb777f71b2097b9560498 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour {
[HideInInspector]public float HeighToRoof = 0f;
private CharacterControl CharactorCTL;
private CameraControl CameraCTL;
// private readonly float GRAVITY = 0.98f;
private void Start () {
CharactorCTL = GetComponent<CharacterControl> ();
CameraCTL = GameObject.Find ("Main Camera").GetComponent<CameraControl> ();
}
void Update () {
HeighToRoof = getHeadHeigh ();
float dx = Input.GetAxis ("Horizontal");
float dy = Input.GetAxis ("Vertical");
Vector3 direction = transform.right * dx + transform.forward * dy;
CharactorCTL.Move (direction, CameraCTL.getForward(5f));
}
public float getHeadHeigh () {
RaycastHit hit;
if (Physics.Raycast (transform.position, transform.position + Vector3.up, out hit)) {
return transform.position.y + hit.distance;
}
return 100f;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment