How do I get a prefab to know who made it?

var spellOne : Transform;
var coolDownOne : float;
var timerOne : float;

function Update () {

			if (Input.GetButton ("Cast1")) {
				if(coolDownOne < timerOne) {
				var instanceBulletOne = Instantiate(spellOne, transform.position, transform.rotation);
				timerOne = 0;
				if(coolDownOne > timerOne) {

So this is the basis of my spell system. It works beautifully. I press a button I’ve called Cast1 and it instantiates a prefab that functions as whatever spell I would like. I have one that acts as a fireball, another that works as a wall, and some others I’m toying with. I have a turret and two players using these spells right now, and I would like to use them with enemies once I get to that point as well, ideally.

What I need, though, is the ability for those prefabs to know who cast them. If Player1 casts a homing missile, I want it to be able to check for the nearest enemy and put that enemy into its Target variable. If Player2 casts a Blink spell, I want it to know that Player2 is the one who needs to move forward by a few feet. You get the idea.

How would I go about approaching that?

One thought:


on the prefab add a script/method named SetInitiator that accepts a GameObject parameter; you can of course call those whatever you want. The prefab now knows what GameObject called it.