Created
January 9, 2018 13:44
-
-
Save tsubaki/81926aade81d5c9c6d0f2a659a47524f to your computer and use it in GitHub Desktop.
キャラクターの移動
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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
[RequireComponent(typeof(Animator))] | |
public class MoveCharacter : MonoBehaviour | |
{ | |
private int idX = Animator.StringToHash("x"), idY = Animator.StringToHash("y"); | |
private Animator animator = null; | |
void Start () | |
{ | |
animator = GetComponent<Animator> (); | |
} | |
void Update () | |
{ | |
float x = Input.GetAxisRaw ("Horizontal"); | |
float y = Input.GetAxisRaw ("Vertical"); | |
if (Mathf.FloorToInt(x) != 0 || Mathf.FloorToInt(y) != 0) { | |
animator.SetFloat (idX, x); | |
animator.SetFloat (idY, y); | |
transform.localPosition += new Vector3 (x, y) * 0.05f; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment