UnityProjekt/Assets/Scripts/NavMeshUpdater.cs
2020-12-08 10:26:17 +01:00

31 lines
No EOL
686 B
C#

using System;
using System.Collections;
using Pathfinding;
using UnityEditor;
using UnityEngine;
[RequireComponent(typeof(AstarPath))]
public class NavMeshUpdater : MonoBehaviour
{
public Transform player;
private AstarPath _pathfinding;
private GridGraph _gg;
private void Start()
{
_pathfinding = GetComponent<AstarPath>();
_gg = _pathfinding.data.gridGraph;
}
private void Update()
{
if (Mathf.Abs(player.position.x - _gg.center.x) > _gg.width * _gg.nodeSize / 4f)
{
var pos = _gg.center;
pos.x = player.position.x;
_gg.center = pos;
_gg.Scan();
}
}
}