|
I was wondering how it would be possible to create an instance of a prefab and assign a character controller and scripts to it by a code file (preferably in javascript). In my case, the prefab is named Smiley4, and there are two scripts that need to be placed on it when it is instantiated. thanks in advance, 2Tie Edit: Mah, i should probably add my current code for it: var NewModel : GameObject; var P1Charname:String = "Smiley4"; function Start() { Instantiate(NewModel, transform.position, transform.rotation); GameObject.Find(P1Charname+"(clone)").AddComponent(CharacterController); GameObject.Find(P1Charname+"(clone)").AddComponent("Gui_StatDisplay"); GameObject.Find(P1Charname+"(clone)").AddComponent("P1Script"); } Smiley is correctly instantiated, but the scripts aren't added...
(comments are locked)
|
|
You could use GameObject.AddComponent Edit: The code I've set up right now goes var NewModel : GameObject; var P1Charname:String = "Smiley4"; function Start() { Instantiate(NewModel, transform.position, transform.rotation); GameObject.Find(P1Charname+"(clone)").AddComponent(CharacterController); GameObject.Find(P1Charname+"(clone)").AddComponent("Gui_StatDisplay"); GameObject.Find(P1Charname+"(clone)").AddComponent("P1Script"); } It instantiates the object, but nothing is added.
Mar 23 '11 at 12:00 AM
2Tie
edited my answer
Mar 23 '11 at 12:02 AM
efge
Thanks! That helped a lot!
Mar 23 '11 at 12:19 AM
2Tie
(comments are locked)
|

could you put all your scripts into one and have that set as standard on the prefab?
all scripts applied to the player I mean!