Newer
Older
using System.Collections;
using UnityEngine;
public class TerrainLooker : MonoBehaviour
{
[Header("User settings")]
public float gridSize = 1000;
[Header("Autogenerated values")]
public Transform player;
public TerrainGenerator terrainGenerator;
private void Start()
{
GameObject po = GameObject.FindGameObjectWithTag("Player");
player = po.transform;
gameObject.RequireComponentAuto(out terrainGenerator, "terrain generator");
}
private void Update()
{
float hgs = gridSize / 2;
Vector3 ppos = player.position;
Vector2Int pGridPos = new(Mathf.RoundToInt(ppos.x / hgs), Mathf.RoundToInt(ppos.y / hgs));
Vector2Int cGridPos = terrainGenerator.currentGridPosition;
if (pGridPos != cGridPos)
{
terrainGenerator.currentGridPosition = pGridPos;
terrainGenerator.GenerateSurronding(terrainGenerator.crawlStartPosition + (Vector2)pGridPos * gridSize);