Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
キャラクターの移動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