How to AddComponent? C#

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

// Snippet from Character Selection Screen
void OnGUI()
{
		GUI.Box (new Rect (0, 0, Screen.width, Screen.height), "Select Your Character");
		
		if (GUI.Button (new Rect (100,100,200,20), "Character A")) 
		{
			userCharacter = 1;
			//CharacterA CharA = gameObject.AddComponent<CharacterA>();
			Application.LoadLevel("CharacterCreationScreen");
		}

		if (GUI.Button (new Rect (100,160,200,20), "Character B")) 
		{
			userCharacter = 2;
			//CharacterB CharB = gameObject.AddComponent<CharacterB>();
			Application.LoadLevel("CharacterCreationScreen");
		}
}
// Snippet from Character A's script file
void Start()
{
		Debug.Log(CharacterSelection.userCharacter); // cant see it
		
		if (CharacterSelection.userCharacter == 1)
		{
			gameObject.AddComponent<CharacterA>();
		}
		else
		{
			Debug.Log("Not Character A");
		}
}

As always, any help is great appreciated…

For some reason I checked the script on my player object (the one I want to load with AddComponent) and it loaded everything, but its overlapped! Maybe if I destroy whatever script is on the Game Object, before loading new ones…

Destorying the already enabled script in the following way:

Destory(gameObject.GetComponent("CharacterA"));
// then enable

Doesn’t work either. Please someone help.

// add component "My_Component" to GameObject go

My_Component my_comp = (My_Component) go.AddComponent(typeof(My_Component));


// destroy component "My_Component" on GameObject go

Destroy(go.GetComponent(typeof(My_Component)));