To encourage code reuse- i want to import methods and classes defined in my core unityscripts to be imported into other unityscripts. How do i go about this?
Note: An answer here seems too complicated for such a simple thing (i come from Python).
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Sign up to join this communityTo encourage code reuse- i want to import methods and classes defined in my core unityscripts to be imported into other unityscripts. How do i go about this?
Note: An answer here seems too complicated for such a simple thing (i come from Python).
You can use inheritance for this. Have the methods and classes in a common base class that's extended by your classes that share this functionality.
Or you can use composition for this. Have the methods and classes in non-monobehaviour scripts. These will be instantiated as objects in your scripts that share this functionality.
Or you can keep these scripts contained in their own scripts at attach them as components to the objects where you want to use their functionality.
You have lots of options here, personally I'd go the inheritance route, but it depends on the kind of functionality you're sharing between scripts.