UnityProjekt/Assets/Scripts/NavMeshUpdater.cs

31 lines
686 B
C#
Raw Permalink Normal View History

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()
{
2020-12-08 09:14:32 +00:00
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();
}
}
}