Last active
December 14, 2015 22:41
-
-
Save maco1028/34427526e77faad5c92d to your computer and use it in GitHub Desktop.
CharactorMove
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 UnityEngine; | |
using System.Collections; | |
public class CharactorMove : MonoBehaviour { | |
public float walkSpeed = 7.0f; //歩く速度 | |
public float gravity = 10.0f;//重力加速度 | |
private Vector3 velocity;//現在の速度 | |
void Update () { | |
//CharacterControllerを取得 | |
CharacterController controller = GetComponent<CharacterController>(); | |
float SpeedX = 0f, SpeedY = -gravity, SpeedZ = 0f; | |
/////キー入力確認 各キーが押されているか | |
if (Input.GetKey(KeyCode.A)){ | |
SpeedX = -1f; | |
} | |
else if (Input.GetKey(KeyCode.D)){ | |
SpeedX = 1f; | |
} | |
if (Input.GetKey(KeyCode.W)){ | |
SpeedZ = 1f; | |
} | |
else if (Input.GetKey(KeyCode.S)){ | |
SpeedZ = -1f; | |
} | |
velocity = new Vector3( SpeedX , SpeedY , SpeedZ ); | |
//キャラクターコントローラーの移動 | |
controller.Move(velocity * walkSpeed * Time.deltaTime); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment