Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created January 9, 2018 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/81926aade81d5c9c6d0f2a659a47524f to your computer and use it in GitHub Desktop.
Save tsubaki/81926aade81d5c9c6d0f2a659a47524f to your computer and use it in GitHub Desktop.
キャラクターの移動
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