Loading Scripts onto GO before in-game scene

Hi,

What I'd like to do, is to be able to choose a type of character, CharacterA or CharacterB, both with different functionality and load their script onto a my Player GameObject. If I choose CharacterA I should load CharacterA's script, and should be able to use the functionality that I have programmed for that script. If I choose CharacterB I should be able to load that different functionality, so on and so forth.

From What I understand I can use the: FoobarScript fbs = gameObject.AddComponent(); reference in the documentation. I am not getting any errors, just what I want to happen, isnt. Here is a snippet of code to show what is relevent to my problem:

`// GUI Script for the “Select Your Character” Scene

void OnGUI()
{
GUI.Box (new Rect (0, 0, Screen.width, Screen.height), “Select Your Character”);

if (GUI.Button (new Rect (100,100,200,20), "CharacterA")) 
{
    userCharacter = 1; // back up plan? ;x
    CharacterA CharA = gameObject.AddComponent<CharacterA>();
    Application.LoadLevel("CharacterCreationScreen"); // Proceed into game
}
if (GUI.Button (new Rect (100,160,200,20), "CharacterB")) 
{
    userCharacter = 2;
    CharacterB CharB = gameObject.AddComponent<CharacterB>();
    Application.LoadLevel("CharacterCreationScreen"); // Proceed into game
}

}
`

But I dont see the functionality, indicating that the script did not load..while in game. I include a standalone statement in the script, namely, a Debug.Log("hi") and I do see that appear directly after I select CharacterB. But I do not experience the functionality in the in-game scene.

I also disabled any scripts for the Player (GameObject) before running each scene. As always any help is very much appreciated.

What you should probably do is have a "Settings" game object and script that are "global", i.e. when your game starts up, call `DontDestroyOnLoad(mySettingsObject);` This will preserve this object even if you load a new level. So what you can do is select your character, save it into the Settings object, and then when your next level/scene loads, read the value and insert the proper component.

Also, I'm not sure you're calling AddComponent correctly... you want to call it on the game object of your character, and currently, you're calling it on the game object that contains the GUI code. I'm not sure if these are the same (They probably aren't), but you need to call AddComponent on your character's game object in order for this method to work. Something like this:

// This script goes on your character game object.

void Start()
{
     // Get Settings Object somehow, either a reference or via "Find"
     // Settings settings = ...; <-- fill this in

     // These values are made-up, but you can see what I'm getting at.
     if(settings.character == 1)
     {
          AddComponent(typeof(CharacterA));
     }
     else if(settings.character == 2)
     {
          AddComponent(typeof(CharacterB));
     }
}