Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
キャラクターの移動
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
You can’t perform that action at this time.