Adding components via parameter
Is it possible to somehow add a component via a parameter in a function? I want to be able to dynamically add different scripts to a gameobject without using a prefab, but I'm running into problems since classes deriving from monobehaviour doesn't allow the use of new.
The way I'm doing it now is I have a base-component that I add to all items I want to create, and then this component have a reference to an object that doesn't inherit from monobehaviour, but it's becoming messy and I'd like to move away from it.
Your answer
Follow this Question
Related Questions
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. 0 Answers
Component not added to model? 1 Answer
How to pass the variable of a current state machine behavior 0 Answers
can't add script behaviour TMP_SelectionCaret . The script need to derive from MonoBehaviour 4 Answers
Why does unity not see monobehaviour? 2 Answers