#Items

1 messages · Page 1 of 1 (latest)

little saffron
#

How I approach it is to make a script specifically to drop items, attach it to my 'managers' game object, and so when anyone or anything wants to drop an item, it just calls the static method in that script

digital dust
#

is your managers object a singleton? how do you get the reference to it?

#

oh well i guess if its a static function you dont need the reference to a specific manager object

fiery glacier
#

There is no downside to having static members if you are using them in ways that make sense

digital dust
#

i guess that makes sense as far as where to organize the functions

little saffron
#

I'm not sure what the standard way to do it is, but I create a game object and attach scripts to it that serve general functions for the scene. So one could be 'ItemDropper', and have a public static method called DropItem(gameobject item, vector3 position), and then when a player or building wants to drop an item, their script calls ItemDropper.DropItem(myitem, myposition)

digital dust
#

i should probably move the dropItem function to either the items class or the inventory class or something like that

fiery glacier
#

If the function requires zero data from an instance of the class it is inside of, you might as well make it static

digital dust
#

thanks danon

#

thats what i was hoping, but i didn't know if static functions made a huge performance hit or something like that

little saffron
#

😐

fiery glacier
#

Technically speaking, static function perform better than instance functions

#

but it is very minor