Health from an prefab to a object?

I’m trying to make a script that a variable from a prefab passes to an object when instantiated(I already have the instantiate script). But I have litteraly no idea how I’m going to do that. If anyone can suggest some things that I can try, feel free to reply :wink:

Kind regards,
Tom

Draw out what you want to do. You have a health variable. Who are you sending it to? Another script? That’s what public variables are for. A manager? A shared data location? Are you sure that it needs to share it’s health out?

Typically I have a manager in charge of the game. He is a singleton. He also has element registry. So every object on instantiation registers itself to the central registry so I can access it. You could just just a static bucket for that.

I have a abstract script called Entity, a sub-class script called zombie, and a zombie instantiate script. In Entity , I have health variable, that I want to pass to a instantiated zombie, so that I can destroy it when health is equal to or beneath 0. I also have a player class(also sub of Entity), but I have no questions about him.
Is this enough information for a solution?

I think you are just looking for GetComponent().health = 100; or the GetComponentInChildren alternative?

You would need to adjust that for your heiarchy, script names, and variable names.

Just don’t use it in Update loops. Expensive process