ForestManager should ultimately be responsible for planting only and not for caring for them. I don't have that version of the ForestManager script on me now unfortunately. I want to make sure I really understand what's going on here before I continue down the wrong path. I may be wrong, but I somehow think doing this as opposed to having MonoBehavior update each tree as a single entity is not efficient. This grow script is called in the Update() method of the ForestManager script. I have a working forest where the ForestManager.cs script iterates over the list of trees, modifying the scale over time so they grow. I have read numerous posts about why this shouldn't or can't be done, but I have not seen a really good explanation with the alternative to using something like Tree aTree = new Tree(x,y) Ĭan anyone please provide a good reason why instancing via new is not used and if not, what is the alternative with an example? It would be much appreciated!!!īut ultimately I'd like the instanced tree to manage its own lifecycle, i.e., plant a tree (instance) and then let it grow and eventually die (taking place within the Update() method). Alternatively, your script can inherit from ScriptableObject or no base class at all". MonoBehaviours can only be added using AddComponent(). If I do this, I get an error like "You are trying to create a MonoBehaviour using the 'new' keyword. My knee-jerk method for instancing these trees would be to call the Tree constructor with the new keyword. I have another script attached to an empty GameObject that manages the forest by instancing trees from the Tree class. The class ideally creates GameObject primitive cubes that represent the tree. I have created a Tree class that I would like to inherit from MonoBehaviour so that things like growth and death of the tree are handled by MonoBehaviour's Update() method. The main goal of my project is to create a simple generative forest. I'm relatively new to scripting in unity but am familiar with programming in general.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |