Nav Meshes

確認済のバージョン: 4.3

-

難易度: 初級

Want to learn how to create paths for the characters in your games? Looking to make an "On Rails" game? Curious how to perfectly roast a turkey? Stop in an learn 2 of those 3 things. In this lesson we will be looking at navigation meshes and how to implement them in your games. Tutor: Mike Geig

Nav Meshes

初級 Navigation

NavCharScript

Code snippet

using UnityEngine;
using System.Collections;

public class NavCharScript : MonoBehaviour {

    NavMeshAgent agent;

    void Start ()
    {
        agent = GetComponent();
    }

    void Update () 
    {
        if(Input.GetMouseButtonDown (0))
        {
            Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
            RaycastHit hit;

            if(Physics.Raycast(ray, out hit, 100))
            {
                agent.SetDestination (hit.point);
            }
        }
    }
}

FollowScript

Code snippet

using UnityEngine;
using System.Collections;

public class FollowScript : MonoBehaviour {
    
    NavMeshAgent agent;
    
    void Start ()
    {
        agent = GetComponent();
    }
    
    void Update () 
    {
        agent.SetDestination (hit.point);
    }

}

関連するチュートリアル

関連ドキュメント