- Home /
List of scripts?
Hey,
Instead of having multiple scripts as components for an object, is it possible to have a master script component that can hold a list of other scripts, or an array of scripts?
Yes, certainly. But it's unclear what value you're expecting that to add?
I just want to sort my scripts, so that ins$$anonymous$$d of having let's say 10 ability scripts on my player i'd have an "abilities" script with slots to add all my ability scripts.
I expect the same result, it's just for sorting purpose and easy enabling/disabling by ID
I'm still not sure I get it.... component scripts attached to a gameobject can already be sorted and enabled/disabled. Not sure how creating another component with a list of those components helps.
Answer by estevan95 · Apr 11, 2017 at 02:29 PM
Yeah. To do so, Double Jump and Dash should inherit from Ability. With every script inheriting from Ability, you can create a list of Abilities.
class Ability : MonoBehaviour
class Dash : Ability
It seems to work but i can only drag scripts that are already components into the array, not scripts from my project folders? Therefore it's useless?
That's correct - component references need to be an instance of a class, not a class itself.
Thanks, i guess i'll try to find another way to manage my abilities
Answer by FortisVenaliter · Apr 11, 2017 at 05:00 PM
You could store a string array of Class names. It wouldn't give you the drag and drop functionality, or the strict type validation, but it would allow you to add components on demand. Define the array:
public String[] AbilityTypeNames;
You could then do something like this at runtime:
Type abilityType = Type.GetType(AbilityTypeNames[i]);
Ability newAbility = (Ability)gameObject.AddComponent(abilityType);
That would allow you to define the ability classes without instances and spawn the instances as needed at runtime.
Thanks, i'll give this a try, i just wish there was a proper ability system tutorial, like how do every FPS games handle unlocking new weapons and having the player choose from the unlocked weapons using the 1-9 keys
Your answer
![](https://koobas.hobune.stream/wayback/20220612115557im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how can i check if there is a blanc spot in my list 3 Answers
A node in a childnode? 1 Answer
Storing instances of a script in a list. 0 Answers
Looping through Button Array and checking for OnClick 0 Answers