- Home /
Portal doors and exits. Can you set up one script to handle tranporting of the character to the exit?
I have two door gameobjects, and inside they have a quad that is used as the trigger, and then an exit for where the PC is supposed to be placed. One works fine but when I add another with the same script, the trigger on the second door transports my character back to the first doors exit position (which is in front of the second door)
My script is just this one function that moves the collider to the exit position:
function OnTriggerEnter (other : Collider) {
other.transform.position = GameObject.Find("Exit").transform.position;
}
Does it have a problem with me trying to Find() the exit? Why wouldn't it be using the script's gameObject parent to find the Exit associated with it? I'm sorry if this has come up before, but I couldn't find anything on the subject. I could have been using the wrong words to search, because I was getting a lot of posts relating to Valve's Portal.
Answer by madman24k · Jul 29, 2014 at 04:12 PM
Never mind, I got it. It was just simply adding a var in the script and setting it to my Exit object's transform in Unity. I feel silly getting stuck on something that seems so simple. Here's my code in case any other beginners come by looking for this info:
var exit : Transform;
function OnTriggerEnter (colObj : Collider) {
colObj.transform.position = exit.position;
}