Last active
January 3, 2016 00:39
-
-
Save Buravo46/8383921 to your computer and use it in GitHub Desktop.
【Unity】3Dのオブジェクトをキーボードで前後左右に動かせるスクリプト。
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 3DCharaControlScript : MonoBehaviour { | |
public Vector3 SPEED = new Vector3(0.05f, 0.05f, 0.05f); | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () { | |
// 現在位置をPositionに代入 | |
Vector3 Position = transform.position; | |
// 左キーを押し続けていたら | |
if(Input.GetKey("left")){ | |
// 代入したPositionに対して加算減算を行う | |
Position.x -= SPEED.x; | |
} else if(Input.GetKey("right")){ // 右キーを押し続けていたら | |
// 代入したPositionに対して加算減算を行う | |
Position.x += SPEED.x; | |
} else if(Input.GetKey("up")){ // 上キーを押し続けていたら | |
// 代入したPositionに対して加算減算を行う | |
Position.z += SPEED.z; | |
} else if(Input.GetKey("down")){ // 下キーを押し続けていたら | |
// 代入したPositionに対して加算減算を行う | |
Position.z -= SPEED.z; | |
} | |
// 現在の位置に加算減算を行ったPositionを代入する | |
transform.position = Position; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment