I have attached a NavMeshAgent to model, and it works.
To debug where the NavMeshAgent wants to go, I have attached a LineRenderer to my model.
I want my LineRenderer to point in the direction where the NavMeshAgent is aiming at / wants to go at.
I have therefore written a script and attached it to the model.
It works, but I think the LineRenderer points somewhere else, not where the NavMeshAgent wants to go.
Would anybody be willing to revise my code?
I have attached it below.
Thank you very much!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class navlaser : MonoBehaviour
{
private LineRenderer _lr;
private UnityEngine.AI.NavMeshAgent _na;
// Use this for initialization
void Start ()
{
_lr = this.GetComponentInChildren<LineRenderer>();
_na = this.GetComponentInChildren<NavMeshAgent>();
}
// Update is called once per frame
void Update ()
{
_lr.SetPosition(1, _na.transform.position);//set the line-renderer's endpoint to where the navmeshagent "aims" / wants to go
}
}