#Hello! I'm stuck on a little something I
1 messages ยท Page 1 of 1 (latest)
I have a number of gameobjects, call them friends, who all do their own thing. They all have separate scripts which derives from another 'Friend' script, which has a bunch of across the board stuff, health, speed, what number they are in terms of when they were added to the scene, etc.
I have a specific friend (call him J) who's gimmick is that he impersonates others, so I've set his script up to periodically add other friends' scripts to himself, then eventually remove and replace them with another script, forever.
My problem is, all these scripts are deriving from 'Friend', but J derives from 'Friend' as well, as he needs to in order to have stats and such. So what ends up happening is J ends up with two sets of variables, 2 healths, 2 speeds, 2 booleans which end up really messing up one of the other friends' scripts.
What I'm trying to do if at all possible is make it so when new scripts get added, they somehow derive from the existing instance of Friend in J's script, rather than deriving from a new instance.
I've tried making J not derive from Friend and just do standard MonoBehaviour with all the Friend stuff necessary inside his own script, but adding the scripts adds Friend to him anyway.
I hope I wrote this in a way thats easy to understand. Any insight or thoughts would be appreciated.
it sounds like you need to make Friend a totally separate script rather than having your other scripts extend it, composition instead of inheritance
Occam's Razor ๐ฉ
is there anything major that would change from this?
like filesize, or uhhhh word escapes me
speed of game?
jesus
not really, there's some small overhead per unity object so having more scripts uses slightly more memory, but it probably won't be significant unless you have like a million of these things
Uhhhh how about like a hundred?
you definitely won't notice it
besides, sounds like you were ending up with a bunch of duplicated fields in memory already ๐
