Для нестатического поля, метода или свойства Chunk.generate() требуется ссылка на объект. Я хотел сделать так что бы из 1го скрипта:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TerrainMain : MonoBehaviour
{
private void Start()
{
Chunk.GEN();
}
}
Запускалась функция GEN. которая уже и выполняет дальнейшие действия во 2м скрипте:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Chunk : MonoBehaviour
{
public GameObject currentBlockType;
public float smooth = 0;
public float multiplier = 0;
public int cols = 50;
public int rows = 50;
public bool CombineChunk;
private Vector3 myPos;
private Transform thisObject;
static private GameObject thisobjscr;
private void Start()
{
thisobjscr = gameObject;
thisObject = gameObject.transform;
}
public static void GEN()
{
generate();
}
public void generate()
{
myPos = this.transform.position;
for (int x = 0; x < cols; x++)
{
for (int z = 0; z < rows; z++)
{
float y = Mathf.PerlinNoise((myPos.x + x) / smooth, (myPos.z + z) / smooth) * multiplier;
y = Mathf.Floor(y);
GameObject newBlock = GameObject.Instantiate(currentBlockType);
newBlock.transform.position = new Vector3(myPos.x + x, y, myPos.z + z);
newBlock.transform.SetParent(thisObject);
if (CombineChunk == true)
{
StartCoroutine(TimerForCombineWait());
}
}
}
}
IEnumerator TimerForCombineWait()
{
CombineChunk = false;
print("waiting for world stabilization: " + Time.time);
yield return new WaitForSeconds(1);
print("world stabilized in " + Time.time);
Combine();
}
public void Combine()
{
MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>();
CombineInstance[] combine = new CombineInstance[meshFilters.Length];
int a = 0;
while (a < meshFilters.Length)
{
combine[a].mesh = meshFilters[a].sharedMesh;
combine[a].transform = meshFilters[a].transform.localToWorldMatrix;
meshFilters[a].gameObject.SetActive(false);
a++;
}
transform.GetComponent<MeshFilter>().mesh = new Mesh();
transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine);
transform.gameObject.SetActive(true);
gameObject.transform.position = new Vector3(0, 0, 0);
}
}
Unity выдает ошибку как раз в public static void GEN
Спасибо.