- Home /
Question by
116 · Jan 22, 2012 at 03:22 AM ·
gameobjectassets
Creating a script instance from an asset
What would be the code to clone a script from the resources folder and put it into a GameObject? I haven't been able to find anything in the scripting reference about this.
Comment
Best Answer
Answer by Lo0NuhtiK · Jan 22, 2012 at 06:21 AM
Unity ScriptReference - AddComponent
Test->
var nameOfScript : String ; //set name in inspector
function Update(){
if(Input.GetKeyDown(KeyCode.X)){
gameObject.AddComponent(nameOfScript) ;
}
}
press X, and now you got your script added.
Oh, I was trying to instantiate the Resources.Load(scriptname). Thanks!