- Home /
Attach a script to GameObject in a DLL
Hello,
I am writing a plugin for Unity using C#.
In my code, I create a GameObject and want to attach a specific c# script to it.
Is this possible at all? I know I can easily attach a c# script to a GameObject while in a specific Unity project, but can I do this in a DLL? If so, where should my prepared c# scripts be placed? How do I address them when trying to attach them?
I tried this:
bullet.AddComponent<BulletScript>();
where bullet is a GameObject and BulletScript is the class in my c# script, but MonoDevelop does not recognize "BulletScript".
You mean the script isn't a part of your DLL? If not then you can use the string version of AddComponent("SomeComponent") which will do it for you, if it is then it should just work...
You can also add a reference to the Unity project, but of course that's pretty pointless for a generic plugin.
One other thought is that you have some namespace issue going on - if you right click BulletScript in $$anonymous$$D then it should offer a Resolve option if it is that.
Your answer
Follow this Question
Related Questions
AddComponent not working 3 Answers
Copy a script from one gameobject to another? 1 Answer
GO.AddComponent just adds an empty Script 1 Answer
Calling Android NDK function from Unity Script 0 Answers
Unity editor scripts stopped working. 0 Answers