1
\$\begingroup\$

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).

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Note that Unityscript is not Javascript. Searching for Javascript solutions might not be useful. \$\endgroup\$ Commented Feb 17, 2015 at 19:40
  • \$\begingroup\$ Specifically he mean's that link has nothing to do with UnityScript/JavaScript-within-Unity. \$\endgroup\$ Commented Feb 17, 2015 at 22:23

1 Answer 1

2
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.