Ok so I’m making a small 2d survival game and I made a little forest.
The forest is made out of empty objects which spawn tree prefabs at their locations every x seconds as their childs. The problem is that they will keep spawning new trees over and over again, so to fix this I made a bool that keeps track if there is a tree there or not. By making the bool false in the editor, the script will spawn a new tree. This is working as expected.
Now here’s my problem. The trees are being cut by a script which is placed on the tree prefabs, which only spawn when the game starts. (in the Start() function). I am trying to change the bool with the following command which should change the doesTreeExist boolean to false, but it doesn’t.
transform.parent.GetComponent<SpawnTrees>().doesTreeExist = false;
I do not understand why it doesn’t change the boolean. Is it because the tree is only instantiated when the game starts? If so, what would be a better way of making the trees?
I will also point out that the command is not executed at the start of the game, just when the player cuts a tree down.