Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active May 15, 2021 16:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/4f3600c519f00b477a3357a58a205fc5 to your computer and use it in GitHub Desktop.
Save tsubaki/4f3600c519f00b477a3357a58a205fc5 to your computer and use it in GitHub Desktop.
キャラクターの移動1
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
using UnityEngine.AI;
public class MoveMobile : MonoBehaviour {
NavMeshAgent agent = null;
void Start () {
agent = GetComponent<NavMeshAgent> ();
}
// Update is called once per frame
void Update () {
// 入力を取得
var v1 = CrossPlatformInputManager.GetAxis ("Vertical");
var h1 = CrossPlatformInputManager.GetAxis ("Horizontal");
var v2 = CrossPlatformInputManager.GetAxis ("Vertical2");
var h2 = CrossPlatformInputManager.GetAxis ("Horizontal2");
// スティックが倒れていれば、移動
if (h1 != 0 || v1 != 0) {
var direction = new Vector3 (h1, 0, v1);
agent.Move (direction * Time.deltaTime);
}
// スティックが倒れていれば、倒れている方向を向く
if( h2 != 0 || v2 != 0){
var direction = new Vector3 (h2, 0, v2);
transform.localRotation = Quaternion.LookRotation (direction);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment