Hey guys.
I understand what objects are, and instances of the objects… in other engines that is. In unity I’m a bit confused. So heres my story for today and questions I’ve got.
I have a prefab of a tree object that I made. Has a script “Chop_Tree”. I also have a prefab of my Player, with a Script Player(for when I make added animations and so forth I can port my scripts over rather easy if I get side-ways some how).
I’m going to try different approaches tomorrow to solve my problem, but I just wanted advise and perhaps tips before I do.
Here is most likely where I went wrong. In the Chop_Tree script I have it linked to the player in the inspector to make sure the player is within a certain distance to the tree to enable him to chop it(its a click to move 3rd person view kind of game - so it disables his move for the time period unless double clicking instead of single to leave). When he starts to chop the one tree - ALL the trees animate as if being hit by the player also, all fall as well… heh.
I’m a bit unsure how to approach the correction to this problem since as I said my prefab is linked to the player.
My first approach is going to be to add onto the script to of Chop_Tree a distance check on the tree that the player is truly by, and if hes not but the other trees ignore/exit… but this sounds like its going to be very slow if I start to get a lot of trees down, and doesn’t seem to be the best method. I’m not really to comfortable with arrays only been programming for 7 months or so, so perhaps its time to learn how to use them to assist in this?
I’m over all wondering a few things.
- What are common approaches used to check for situations like this to apply only the wanted out come to one instance of a object?
- Instead of iterating all trees, to make sure that only the one the player is by is changed, would it be faster to perhaps add the only tree I’m changing to some type of list?
Just looking for a little guidance and knowledge to advance myself, I feel a bit confused by this one.
As always thanks community.