Script to parent player to object

I’m trying to build a fairly complex elevator script (10 elevators and 7 floors)

I’m trying to make the player parent to an elevator platform (elevator name is portOneEle) when the player triggers/collides with the collider called portOneEleArea (which is a box collider on top of the platform).

This is what I have, which, intuitively seems like I’m on the right track but… what the hell do i know?!

var Player:Transform;

function OnCollisionEnter(collision : Collision) {
    Player.parent=portOneEle;
    }
function OnCollisionExit(collision : Collision) {
    Player.parent=null;
    }

problem is… the script doesn’t know what the object portOneEle is, and I’m not sure how to pass that into the script.

If you attach your script to the elevator you could

function OnCollisionEnter(collision : Collision)
{
    collision.transform.parent = transform;
}

function OnCollisionExit(collision : Collision)
{
    collision.parent = null;
}

Or to make sure you parent the correct object (Player in your case) you could instead:

function OnCollisionEnter(collision : Collision)
{
    if(collision.gameObject.CompareTag("Player"))
        collision.transform.parent = transform;
}

Though in this case you would have to make your Player object tagged as “Player”. See Tag Manager