Instantiate from transform INSIDE of G.O.?

Please help. any advice is appreciated.

I created a magic fireball throwing enemy, when there is only one enemy the fireball starts at the my_spell_source transform as expected… however, when I have more than one, all fireballs start at the source of a single enemy. I assume that each iteration of the enemy object is using the my_spell_source of the first enemy in the scene… but I’m not sure what is a better way to give each its own origin.

Is there a way to only a.Find an object by name that is ONLY inside of each object ?

here is a snippet of the code.

// *** START ***
	void Start () {
		
		target = GameObject.Find ("Player").transform;
		my_player = GameObject.Find ("Player");
		my_player_script = my_player.GetComponent <GUI_HUD> ();

		// spell source
		my_spell_source = GameObject.Find ("enemy_spell_source");






	public void magic_attack()
	{
		magic_interval = 6.0f;
		magic_next = Time.time + magic_interval;
		
		// anim
		//int magic_hit_dmg = 21;

		GameObject fireball_clone;
		fireball_clone = Instantiate(fireball_prefab_source, my_spell_source.transform.position, my_spell_source.transform.rotation) as GameObject;
		//_clone = Instantiate(source, position, rotation);
		Vector3 shoot_angle = my_spell_source.transform.forward;
		fireball_clone.rigidbody.velocity = shoot_angle * 100 * Time.deltaTime;
	}

Yes, you’re correct. GameObject.Find() will return the first match that it finds and then it will stop searching. Assuming that this script is attached to each enemy, then what you want to use is the gameObject property of MonoBehaviour.

A couple of notes:

I see that you are only using my_spell_source to get to its transform property. So, you could do something like private Transform my_spell_source; as a field, and then in Start do my_spell_source = transform;

Also, you’ve probably read that GameObject.Find() is very inefficient, so you should use it as little as possible. In the Start() you could reduce it to call Find only once and use properties of the returned object to get the other values.

GameObject.Find

MonoBehaviour.gameObject

I think you want to use transform.Find instead.