Hello,
Since im quite new in development and programming, i dont know much about how things are actualy called.
I started a Project, made the Joystick and worked on the camera to fit my needs and it all worked out well. My next point on the list was to make a ground Instantiator that spawns the ground on game start depending on the used resolution on awake that works in a script from the camera. Writing the script was quite simple and runing tests on it worked only under one condition: to not have a prefab attached to the script… having a prefab attached on the public gameobject ground to instantiate it make unity unable to even run the game. Overloading the whole computer and filling the memory slowly but without even reaching a started playmode.
This made me think that its more about unity itself then about the script that might make problems.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GroundInstanciator : MonoBehaviour
{
public GameObject ground;
private Transform Ground;
private float groundSizeX;
private float groundSizeY;
private float screenX;
private float screenY;
private int groundAmountX;
private int groundAmountY;
public float edgeX;
public float edgeY;
void Start()
{
Ground = GameObject.Find("Ground").transform;
groundSizeX = ground.GetComponent<BoxCollider2D>().size.x;
groundSizeY = ground.GetComponent<BoxCollider2D>().size.y;
screenX = GameObject.Find("Main Camera").GetComponent<ScreenView>().viewX;
screenY = GameObject.Find("Main Camera").GetComponent<ScreenView>().viewY;
groundAmountX = (int)groundSizeX * (int)(screenX / groundSizeX + 2);
groundAmountY = (int)groundSizeY * (int)(screenY / groundSizeY + 2);
for(int i = -groundAmountX; i < groundAmountX; ++i)
{
for (int j = -groundAmountY; i < groundAmountY; ++j)
{
Vector3 pos = new Vector3(i * groundSizeX, j * groundSizeY, 0);
Instantiate(ground, pos, Quaternion.identity, Ground);
}
}
edgeX = screenX + groundSizeX;
edgeY = screenY + groundSizeY;
}
}
thats the whole script. Attaching a prefab on the public GameObject ground via the inspector made Unity unable to start a tryrun. (im talking not about building and running a game, im talking about pressing the playbutton in the middle top of unity editor.)
please help since i cant see my problem.