Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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