Last active
December 28, 2015 13:38
-
-
Save kankikuchi/7508626 to your computer and use it in GitHub Desktop.
Unity 移動+視点移動(移動改善)
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
void PlayerMove(){ | |
//速度初期化 | |
velocity = Vector3.zero; | |
//キー入力確認 各キーが押されているか | |
if (Input.GetKey(KeyCode.A)){ | |
velocity -= transform.right; | |
} | |
else if (Input.GetKey(KeyCode.D)){ | |
velocity += transform.right; | |
} | |
if (Input.GetKey(KeyCode.W)){ | |
velocity += transform.forward; | |
} | |
else if (Input.GetKey(KeyCode.S)){ | |
velocity -= transform.forward; | |
} | |
//バーチャルパッドのオブジェクト取得 オブジェクト名 : Joystick | |
GameObject Joystick = GameObject.Find("Joystick"); | |
//バーチャルパッドのオブジェクトのスクリプトを取得 スクリプト名 : MpJoystick | |
MPJoystick JoystickScript = Joystick.GetComponent<MPJoystick>(); | |
//パーチャルパッドがタップされている マウスではタップ出来ない | |
if(JoystickScript.tapCount > 0){ | |
//スピードを設定 | |
velocity += transform.right * JoystickScript.position.x; | |
velocity += transform.forward * JoystickScript.position.y; | |
} | |
//移動スピード設定 | |
velocity *= walkSpeed; | |
//下を向いていても上に飛ばないように重力を代入 | |
velocity.y = -gravity;//重力設定 | |
//キャラクターコントローラーの移動 | |
controller.Move(velocity * Time.deltaTime); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment