Unity, C# and OOP

i have a generic question that might be really dumb, but i dont get it.

im writing code for a generic turret to shoot a generic missile. i want the turret to hold an array (public, set by me for now) of characteristics, and i want it to use this array to initialize the behaviour script on the missile.

so i got a turret object with a turretScript: in this script there is a public variable “array”.
the turret instantiates a missile prefab that has a missileScript attached. i want this script’s own “array” (also public) to be initialized from the turretScript that instantiates the missile:

approach 1.

`Instantiate(missile, otherParameters);

missileScript ms = missile.transform.GetComponent();

ms.initializeMissile(array);`

as in my prevois experience with OOP i expected this to work like this: instantiate a missile with his script attached to it, then access THAT INSTANCE of the missileBrain class, then change the internal values of THAT INSTANCE.
instead, every time initializeMissile() was called, it changed the values in the “prototype” class in my assets folder. thus changing the variables for every successive missile spawned. (this ofc caused a massive lot of problems).

approach 2.
learning from the prevois result, i cahnged it to be the same as approach 1, but the instantiate() is called AFTER getcomponenet() and initialize(). and this works. every time ANY missile is launche by ANY turret, the missileScript class is changed, and therefore i have to change it back when i want to launch a completely standard missile.

now finally the question: is this intended? if it is… WHY is this intended? isnt one of the points of OOP the fact that you can work on a single instance of class Something whithout affecting the “prototype” for all future objects of type Something? or am i doing something wrong and im actually telling the script to change the class definition instead of the specific instance?

i hope ive been clear, although i probably have not. im sorry fot the long post but…

The approach 1 is almost right but with a slight issue.

You can instantiating a new missile using your missile object and then you are getting the reference to missileScript from your missile object and not the newly instantiated missile. Your approach should be:

// We instantiate a missile and get a reference to it
GameObject newMissile = (GameObject) Instantiate (missile, otherParameters);
// Now get the missileScript from this newly instantiated missile
missileScript ms = newMissile.transform.GetComponent();
ms.initializeMissile(array);

Now here you are accessing the missileScript from the newMissile and not your prototype missile.