How Can I Set who Launched the Misile in my game

I have many characters and many Misile kinds so I want to access from the misile script to the Character who instantiated it to increment its score if it hits the enemy. I tried used One but it changes all the Misiles in the Scene to the last one that launched the Misile.

this is the Script of the one to Launch the misile, but it change the Fields of all the misiles in the scene even if they was not instantiated by It

public class LAUNCH : MonoBehaviour {
    public bool CounterInit = true;
    public float CD;
    public GameObject MisileA;
    public Transform LaunchPoint;
    int Rotation = 0;

    void Update ()
{
        if (Input.GetKeyDown("space") && (CD == 0.00f))
        {
            Instantiate(MisileA, LaunchPoint.position, Quaternion.Euler(0, 0, Rotation));
            CD = 15.0f;
            MisileA.GetComponent<MisileA>().MisileOwner = this.gameObject;
        }
}

and the code of the misile is

public class MisileA: MonoBehaviour{
    Vector2 PositionIn;
    float Diverg = 30.00f;
    float XActual;
    float YActual;
    public GameObject MisileOwner //Who ever Launces this Misile

    void OnCollisionEnter2D(Collision2D coll)
    {
        if (coll.gameObject.tag == "ENEMY")
        {
            coll.gameObject.GetComponent<INIT>().Anger + = 1;
            coll.gameObject.GetComponent<INIT>().Health+ = 1;
            coll.gameObject.GetComponent<INIT>().Score  - = 20; //The one who is HIT
            MisileOwner.GetComponent<INIT>().Score += 100; //The one who LAUNCHES
        }
    }

** Please note in the below I’ve used the correct spelling of missile for my variables but maintained your variable names as is. **

Add a function to your Missile script along the lines of:

void ownedBy(gameObject newMissileOwner){
MisileOwner = newMissleOwner;
}

Then change line 14 in your update to:

MisileA.GetComponent<MisileA>().ownedBy(playerGameObject);

playerGameObject is going to be the game object of the player who is able to press space (which you should know somewhere in your game). this.gameObject isn’t going to work for you here i don’t believe.

Thank you for Answering and I’m Sorry for the orthography. That works but I don’t know how to trace who was the one that Launched de Missile. So I want to storage somehow the owner of the Missile in the Missile script at the moment it is instantiated.

In the provided code you are using the pressing of space to be the person launching the missile. That makes me believe that the only person who could launch the missile in the provided code is the player.

The other occasions (computer controlled players?) i would imagine you would have another method that spawns the missile and at that stage you would have the related game object. You would call the same line and instead of using the “playerGameObject” you would just use whichever one is launching that missile.

I need to make it this way because Computer controlled players can turn into Playable characters keeping its score and register, I will only change the way it gets the input when the Character is not cotrolled by the Player.

You’re setting the value on LAUNCH.MisileA, which is the prefab you’re instantiating from, but is not the new missile that you created. You’d want to do:

var newMissile = Instantiate(MisileA, LaunchPoint.position, Quaternion.Euler(0, 0, Rotation)) as GameObject;
newMissile.GetComponent<MisileA>().MisileOwner = this.gameObject;

Also, calling the variable in LAUNCH the same name as the class (MisileA) is confusing, you should change it.