Nav Mesh Agent
1.When completed the Mesh Groud(make of Plane) and Mesh Wall(make of Cube),Static,Window-Navigation-bake,bake the scene,static-get rid of Navigation.bake.
2.component-avartor,rigidbody,character controller,nav mesh agent,the script bellow. but that is not the effect I want...
using UnityEngine;
using System.Collections;
public class PlayerAuthMove : MonoBehaviour
{
private Animator mAnim;
public float MoveSpeed = 2f;
private NavMeshAgent mAgent;
// Use this for initialization
void Start()
{
mAnim = this.GetComponent<Animator>();
mAgent = this.GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Vector3 mPos = Input.mousePosition;
Ray mRay = Camera.main.ScreenPointToRay(mPos);
RaycastHit mHit;
if (Physics.Raycast(mRay, out mHit))
{
if (mHit.collider.tag == "Ground" || mHit.collider.tag == "Wall")
{
Vector3 mTarget = mHit.point;
transform.LookAt(mTarget);
float mDistance = Vector3.Distance(mTarget, this.transform.position);
if (mDistance > 4F)
{
mAnim.SetBool("IsWalk", true);
}
mAgent.SetDestination(mTarget);
}
}
}
}