-1

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.

trahane
  • 701
  • 6
  • 16
  • 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 Answers1

2

If I don't misunderstand you, that's possible.

  1. Read C# codes from a text file using System.IO.File.ReadAllText(...) or Resources.Load(...) as TextAsset.
  2. Use CSharpCodeProvider to dynamically generate a dll.
  3. Load the Component type from the dll into the AppDomain.
  4. Create a object of the type.
  5. Attach it to the gameObject.

More on this here: How to load a class from a .cs file

Community
  • 1
  • 1
zwcloud
  • 4,546
  • 3
  • 40
  • 69