Teleporting to were I built the prefab (portal)

So Im making a portal-like-game but i cant get past one thing. Every time I go through a orange or blue portal that I shot (It just instantiates a clone) I get teleported to were i originally built the portal’s prefab on the map.

Is there a way I can make the original coordinates equal “null” until I shoot the portal which assigns the coordinates then, and still have them link to eachother automatically?

ps. I have this code for teleporting (java):

var destination : Transform;

function OnTriggerEnter(other : Collider) {
if (other.tag == "Player") {

other.transform.position = destination.position;

other.transform.rotation = destination.rotation;



heres the code for instantiating the portals:

var portalToSpawn : Transform;

var bullet : Transform;

var time : int;

var portalIsActive : boolean;

function OnTriggerEnter(other : Collider){

if(portalIsActive == false){

gameObject.Destroy(gameObject, 1.0);
portalIsActive = true;
Instantiate(portalToSpawn, transform.position, transform.rotation);



(I have never played portal, so I don’t know how the game works but…)

I would set your “teleporter gun” script to bounce back and forth from shooting the two different portal prefabs, each with its own tag (“portal1” “portal2”). On each portal I would have the script search for duplications of itself, and destroy them. While at the same time search for the portal with the other tag and (if found) set it as the destination, or (if not found) deactivate the ability to teleport the player.

This would limit the player to only two portals (or as many as you wanted), and always have active coordinates (once both portals were instantiated).

I can through together some mock code for you, but I am much sharper with C# then JS.