I need to Instantiate a prefab at the same location where a different object was destroyed.,

This is my script so far. Instead of creating object b where object a was destroyed, it creates it at object a’s last position before it was destroyed. Any ideas on what I’m doing wrong?

,

True, I'm not to sure about AR Projects but as far as building an Android App. Try some more tutorials to give you more an idea of how to build and run the app. Sometimes the answer is within other insights of the answer. For example, you might research how to build a 2D or 3D Android apps and be able to pick up more information on how to build an android apk file more accurately without specifically looking a AR Projects.

1 Answer

1

You can use the script below:

void OnTriggerEnter (Collider other) {
  if (other.gameObject.tag == "Plys2") {
    Vector3 spawnLoc = other.ClosestPoint (transform.position);
    Quaternion spawnRot = objToDestroy.transform.rotation;
    Instantiate (objToSpawn, spawnLoc, spawnRot);
   Destroy(objToDestroy);

  }
}

Good day, your answer is correct, (upvoted) but as a good practice, if you want to "replace" an object for another, once you know the position is better to destroy the 1st object and then instantiate the 2nd, so i reccomend to swap the las 2 lines Destroy(objToDestroy); Instantiate (objToSpawn, spawnLoc, spawnRot); Bye!