I want to attach a script to a empty gameObject
at runtime
using addComponent
.
But, I don't want to drag the script directly into the project, I want to first build the project and the go into the build folder and drag it there.
After the game starts, I want to load it from there and attach it to the empty gameObject
.
Asked
Active
Viewed 1,244 times
-1

trahane
- 701
- 6
- 16

pitar parkar
- 13
- 3
-
What do you mean by loading them? – Programmer Sep 03 '16 at 13:40
-
Getting the script from the build directory and attaching it using addComponent – pitar parkar Sep 03 '16 at 13:43
-
Still doesn't make sense. Anyways, you should edit your question and remove everything in it, then ask the question in a different way that people can understand. You can also post link to images to describe what you are trying to do. By doing this, you will likely get an answer. – Programmer Sep 03 '16 at 13:51
1 Answers
2
If I don't misunderstand you, that's possible.
- Read C# codes from a text file using
System.IO.File.ReadAllText(...)
orResources.Load(...) as TextAsset
. - Use
CSharpCodeProvider
to dynamically generate a dll. - Load the
Component
type from the dll into the AppDomain. - Create a object of the type.
- Attach it to the gameObject.
More on this here: How to load a class from a .cs file