Created
July 3, 2017 14:31
-
-
Save tsubaki/c81cb6033ddc1341fc1ec1e6e4d3f049 to your computer and use it in GitHub Desktop.
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 { | |
Transform cameraTransform; | |
NavMeshAgent agent = null; | |
void Start () { | |
agent = GetComponent<NavMeshAgent> (); | |
cameraTransform = Camera.main.transform; | |
} | |
// 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"); | |
var cameraForward = Vector3.Scale(cameraTransform.forward, new Vector3(1, 0, 1)).normalized; | |
if (h1 != 0 || v1 != 0) { | |
Vector3 direction = cameraForward * v1 + cameraTransform.right * h1; | |
agent.Move (direction * Time.deltaTime); | |
} | |
if( h2 != 0 || v2 != 0){ | |
Vector3 direction = cameraForward * v2 + cameraTransform.right * h2; | |
transform.localRotation = Quaternion.LookRotation (direction); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment