Getting Components with the same name

I am trying to create an object that can be affected by more than one joint at run-time. When a new object B is attached to my original object A, A adds a configurable joint to itself and takes B as its connected rigid body. The problem occurs when a new object C wants to attach itself to the original object A. A adds a new configurable joint to itself, but when I use the GetComponent() function to get the configurable joint, it returns the first joint created so changing the connected body that joint replaces B (i.e object C replaces B) and the joint created for C cannot be accessed leaving the connected body to be none. How can I reference the joint created for C without replacing that for B.

PS: Sorry the question sounds like a riddle that's the best way I can explain it

Use GetComponents instead, which returns an array you can loop through (or store the components yourself in an array when you do AddComponent, so you know which is which)

All I ever get when I try this is

InvalidCastException: Cannot cast from source type to destination type. AudioManagerScript.Start () (at Assets\MIHT_Assets\MIHT_Scripts\AudioManagerScript.js:27)

my code is:

var mySfxAudioSources:AudioSource;

function Start()
{
mySfxAudioSources=gameObject.GetComponents(AudioSource);
}

I'm obviously doing something wrong but I dont know what. I have tried declaring a new array length too(mySfxAudioSources=new AudioSource(20)) but I still get the same problem.

For some reason gameObject.GetComponents(AudioSource) does not seem to return an array try casting whatever it returns into an array. This should work. Try this:

var mySfxAudioSources:AudioSource[];

function Start() { mySfxAudioSources = Array(gameObject.GetComponents(AudioSource)); }