I was trying to add a script programmatically to dynamically generated entities, but was unable to do so. Essentially, this is for a multiplayer game where I need the receiver script to be attached to every enemy object that appears in the scene, and I can’t use the editor since said enemy objects are generated through code. I looked around on the forums a bit, but wasn’t able to find topics that add scripts that already exist, and instead these use the create command. How would I go about adding a script programmatically if it already exists in the assets directory?
You need to pass the script type name, which you can easily grab by opening your script file and finding the following line (usually it’s the first line):