Created
March 28, 2017 10:59
-
-
Save kazumalab/3c5a2122509eb777f71b2097b9560498 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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