Setting variable in prefab from a method called by prefab


Could you please advise me how to change a variable in prefab from method called by the prefab?

This is how I call the method from prefab on collision:

public void OnCollisionEnter2D(Collision2D collision)
        _GSScriptReference.EnemyCollision(transform.position, collision.gameObject.tag, collision, Lives, PointsForKillMe, gameObject);

From Method in different script I want to change variable Lives in the prefab which called the method. I tried several syntaxes, none works for me. Now I have something like this:

EnemyGameObject.GetComponent(FireballScript).Lives = Lives;

EnemyGameobject is the object reference ’ gameObject’ I got while calling the method -

Thanks so much for any help


To clarify a little: I have a main game script. It contains a method every enemy is calling onCollisionEnter2D. I need to change number of lives of the enemy after the collision. I’m passing reference of the enemy gameobject as a parameter of the method call. I can’t figure out how to change variable (nr. of lives) back to the enemy prefab.