I was making a weird chunk system for my game but when I run the project it makes the floors go far away from my player position if you know the solution please tell me also here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Generate : MonoBehaviour
{
public GameObject player;
public GameObject[] floor = new GameObject[1];
private List<float> id = new List<float>();
public float offset = 5;
public float times=6f;
public float yopset=1f;
// Start is called before the first frame update
// Update is called once per frame
void Update()
{
for (float xi = (Mathf.Ceil(player.transform.position.x) - offset); xi < (Mathf.Ceil(player.transform.position.x) + offset); xi++)
{
for (float zi = (Mathf.Ceil(player.transform.position.z) - offset); zi < (Mathf.Ceil(player.transform.position.z) + offset); zi++)
{
if (id.Contains(zi * xi))
{
if (transform.Find("floor").transform.position.x != (xi * zi) / zi & transform.Find("floor").transform.position.z != (xi * zi) / xi)
{
GameObject floors = Instantiate(floor[0], new Vector3(xi * -times, Mathf.Ceil(player.transform.position.y) - yopset, zi * times), floor[0].transform.rotation);
}
}
else
{
GameObject floors = Instantiate(floor[0], new Vector3(xi * -times,Mathf.Ceil(player.transform.position.y)-yopset, zi * times), floor[0].transform.rotation);
}
}
}
}