Skip to content

Instantly share code, notes, and snippets.

@yasuyuki-kamata
Created May 25, 2018 05:41
Show Gist options
  • Save yasuyuki-kamata/340602fa3879d8036e2a182b4225930b to your computer and use it in GitHub Desktop.
Save yasuyuki-kamata/340602fa3879d8036e2a182b4225930b to your computer and use it in GitHub Desktop.
子オブジェクト(プレイヤー)につけたコンポーネント キーボードの十字キーで操作 親オブジェクトからの相対位置で移動する
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