Last active
May 15, 2021 16:05
-
-
Save tsubaki/4f3600c519f00b477a3357a58a205fc5 to your computer and use it in GitHub Desktop.
キャラクターの移動1
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; | |
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