- Home /
Question by
daviddickball · Jun 06, 2015 at 06:45 PM ·
instantiatescaleparenttransform.parent
How to instantiate an object inside parent using parent's scale
I want to instantiate an object inside my enemy gameobject, and to position them relative to the parent, also to use the parent's scale.
So I use:
var exp = Instantiate(Resources.Load("Explosion", GameObject), Vector3(transform.position.x+3,1,transform.position.z+1), transform.rotation);
exp.transform.parent = gameObject.transform;
...this creates the object inside the enemy but is really far away, as the enemy's scale is less than 1.
Comment
I've actually gotten around this by using a dummy object, and getting the coordinates of that.
Wiki
Answer by starikcetin · Jun 06, 2015 at 06:57 PM
Maybe this will work (c#):
GameObject exp = Instantiate(Resources.Load("Explosion", GameObject), new Vector3(transform.position.x+3,1,transform.position.z+1), transform.rotation) as GameObject;
exp.transform.parent = gameObject.transform;
exp.transform.localPosition.Set(3,1,1);
Your answer
Follow this Question
Related Questions
How can I Instantiate a clone as a child of another object, and inherit the parent object's scale? 2 Answers
Instantiate New Gun 1 Answer
Instantiate object as child of scripted objects parent 1 Answer
Help with Instantiate and parents 1 Answer
Instantiate prefab as Child to remove and re-do later 2 Answers