# 【Unityでアプリ開発】<br>ぱーと⑥~キーボード制御~ ## キーボード制御のプログラムです. 「Keyboard_controler.cs」 ```C#: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Keyboard_controler : MonoBehaviour { // Use this for initialization void Start () { } //重力加速度 const float Gravity = 9.81f; //重力の適用具合 public float gravityScale = 1.0f; void Update(){ Rigidbody rb = this.transform.GetComponent<Rigidbody> (); //高さ方向の判定はキーのzとする if ( Input.GetKey("w") ){ Vector3 force2 = new Vector3 (00.0f, 0.0f, 5.0f); rb.AddForce (force2); // 力を加える } //高さ方向の判定はキーのzとする if ( Input.GetKey("s") ){ Vector3 force2 = new Vector3 (00.0f, 0.0f, -5.0f); rb.AddForce (force2); // 力を加える } //高さ方向の判定はキーのzとする if ( Input.GetKey("d") ){ Vector3 force2 = new Vector3 (5.0f, 0.0f, 0.0f); rb.AddForce (force2); // 力を加える } //高さ方向の判定はキーのzとする if ( Input.GetKey("a") ){ Vector3 force2 = new Vector3 (-5.0f, 0.0f, 0.0f); rb.AddForce (force2); // 力を加える } } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up