Object not Instantiating Correctly

Hi there,

I’m trying to instantiate an object relative to a prefab’s position. So within the script attached to the prefab, I setup the function below. Problem is that the instantiated prefab is not being instantiated at the right position.

I’ve used a similar script for another prefab and it’s working fine. Anyone have any idea why this is the case?

void CreateEnemySpeech()
	//instantiate speech
	GameObject instEnemySpeech = Instantiate (EnemySpeech, new Vector3(transform.localPosition.x, transform.position.y+200, transform.localPosition.z), transform.rotation) as GameObject;
	instEnemySpeech.transform.SetParent (BattleCanvas, false);
	EnemySpeechText = EnemySpeech.GetComponent<EnemySpeechContainer> ();
	EnemySpeechText.EnemySpeech.text = "text";
	Destroy (instEnemySpeech, 4f);

Good day.

I reccomend you to replace this

instEnemySpeech.transform.SetParent (BattleCanvas, false);

for this:


and if the position where it apears is not the correctone,m change it via scripitng

instEnemySpeech.transform.position = WhereYouWantPosition ;

Making an object parent/child of another sometimes is complex, becoause if parents have diferent scales and rotations is hard to think each time which should be the correctones… For my experience, is better to first become child/parent, and then move/rotate/scale the objects

If helped, accept the answer! :D

Bye :smiley: