- Home /
transform.position on Instaniated object does not match inspector
When a missile misses the player, I have it instantiate an empty (dud) and assign that as the target.
However, the transform coordinates of the dud show as 0,0,0 ; the coordinates of the prefab. That shows when I use print on the console.
In the inspector, the transform shows as the position that was generated within the script (dudv3).
So the missile heads to the wrong position, 0,0,0, instead of dudv3.
Dud creation code
void NoTarget()
{
Vector3 dudv3 = new Vector3 (transform.position.x, transform.position.y, dudZValue); //creates target for s200 to crash into
Instantiate(dud, dudv3, Quaternion.identity);
Destroy (gameObject, noTargetDestroyTime);
print (dud.transform.position);
}
Targeting code
void Targeting()
{
if (GameObject.FindGameObjectsWithTag ("explosion").Length != 0)
{
target = GameObject.FindGameObjectWithTag ("explosion").gameObject.transform; //changes the target to the explosion
}
if (GameObject.FindGameObjectsWithTag ("explosion").Length == 0)
{
if (GameObject.FindWithTag ("Player").transform.position.z > transform.position.z)
{
target = GameObject.FindWithTag ("Player").transform; //changes the target to the player
}
if (GameObject.FindWithTag ("Player").transform.position.z < transform.position.z) { //if infront of player
if (GameObject.FindWithTag ("dud") == null) { //makes sure the dud gameobject doesn't exist
NoTarget ();
} else {
target = dud.transform;
}//end else
}// end infront if statement
}
}//end Targeting
Your answer
Follow this Question
Related Questions
The instantiated prefab doesn't fire correctly from the player 2 Answers
Instantiate object in front of player? 2 Answers
How to carry over variable (transform.position) and use it as Vector3 for instanitating a prefab 2 Answers
Updating transform.position correctly to instantiated GameObjects 0 Answers
Object keeps moving when using Vector3.Lerp on transform.position 0 Answers