Created
May 25, 2018 05:41
-
-
Save yasuyuki-kamata/340602fa3879d8036e2a182b4225930b to your computer and use it in GitHub Desktop.
子オブジェクト(プレイヤー)につけたコンポーネント キーボードの十字キーで操作 親オブジェクトからの相対位置で移動する
This file contains hidden or 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; | |
public class PlayerMove : MonoBehaviour | |
{ | |
public float PlayerSpeed = 20f; | |
private Transform _parentTransform; | |
private void Start() | |
{ | |
_parentTransform = transform.parent.transform; | |
} | |
private void Update () | |
{ | |
Move(); | |
} | |
private void Move() | |
{ | |
var vertical = Input.GetAxis("Vertical"); | |
var horizontal = Input.GetAxis("Horizontal"); | |
transform.Translate(horizontal * PlayerSpeed * Time.deltaTime,vertical * PlayerSpeed * Time.deltaTime, 0, _parentTransform); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment