- Home /
Instantiate at wrong position
I have a problem and hope someone can help me with this one. I have an enemy, once it is being killed it spawns points which the player can collect. So far this works all well. The problem I am facing is thst the Points do not spawn at the Location where the enemy was defeated, instead they always spawn at the location set in the inspector for the points prefab.
function Death()
{
Destroy (gameObject);
for (var i=0; i < points; i++)
{
var pointsPrefab : GameObject = Resources.Load("Prefabs/Points/Points");
Instantiate(pointsPrefab, transform.position, transform.rotation);
}
}
Answer by abhishek082007 · Jun 14, 2014 at 11:19 AM
well transform.position will spawn the point at a position where the gameobject with that script is attached, instead of "transform.position" try that "Enemy.transform.position"
Enemy is a GameObject variable here..
What abhishek082007 said. transform.position automatically retrieves the transform of the object the script is attached to. You need to organize a variable containing the enemy object and retrieve that transform.
Your answer
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Code only affects first clone? 2 Answers
instantiate at mouse problems 0 Answers