Is this doable in unity

I want to ask to all of you who understand Unity better than I do…please help me…

I have this a gameobject name “A”
within this gameobject I’ve got a script named “Ascript”

We are able to get the script file using GetComponent() to change values within Ascript.

Usually if I wanted to have some other script with the same name which is “Ascript” I created other gameobject with other name that hold Ascript to access and manipulate values within the other Ascript.

Is it doable in unity3, if I had this game object “B”
that holds two or three scripts named “Bscript” and access it dynamically.

in short :
Can I access several components with the same type and same name within a game object. and change values within one script without interuptting other values?

please help me ^^ thx

Your question is honestly pretty unclear, but if your question is: "can I have the same script attached multiple times to a single gameobject" the answer is YES, but it would possibly not work as expected UNLESS you create empty gameobjects that are childs of your original gameobject, and which you name differently. This way, your gameobject, called A, would have for example four childs called A1, A2, A3 and A4, to which you attach Ascript on each. This way, all scripts would be indipendent and easily addressable. To access Ascript in A4, you can simply issue a


Sure, that’s why there are the functions GetComponents and GetComponentsInChildren.

// C#
Ascript[] myAscripts = GetComponents<Ascript>();
myAscripts[0].someValue = 5;