- Home /
Parenting On Trigger not Working?
Hey Everybody! So I have a Ship that has a Box Collider inside it. When My player collides with the Collider, it activates an AI Script. What I was trying to do was that at the same time, have the Player Made a Child of the Ship So that it goes wherever the AI goes, until nessecary. So therefore the Player needs to be Inactive for a variable amount of time. I was using this script but instead of getting parented, the player just goes flying off the edge! Is there a different script that I should use?
UPDATE! I FINALLY FIGURED IT OUT:
var scriptname1 : GameObject;
function OnTriggerEnter(other: Collider)
{
if(other.tag == "Player")
{
scriptname1.active = false;
other.transform.parent = transform.parent;
}
}
function Update () {
if (Input.GetKeyDown ("e")){
Destroy(gameObject);
scriptname1.active = true;
}
}
Thanks for all your help!
Answer by sketchers1 · Aug 09, 2012 at 03:24 AM
Here is the mostly Correct Script, the one thing I cannot figure out is getting out of the ship.
var scriptname1 : GameObject;
function OnTriggerEnter(other: Collider)
{
if(other.tag == "Player")
{
scriptname1.active = false;
other.transform.parent = transform.parent;
}
}
function Update () {
if (Input.GetKeyDown ("e")){
Destroy(gameObject);
scriptname1.active = true;
}
}
Answer by cassius · Aug 09, 2012 at 12:30 AM
Not sure but wouldn't "col.transform.parent = transform.parent;" just be "col.transform.parent = transform;"?
Answer by Ingen · Aug 09, 2012 at 12:49 AM
hallo, I use this, found somewhere here, on a trigger inside the lift
var platform : Transform;
var player : Transform;
function OnTriggerEnter () {
player.parent = platform;
}
and this on a trigger just when exit the lift
var platform : Transform;
var player : Transform;
function OnTriggerEnter () {
player.transform.parent = null;
}
using OnTrigerExit on the trigger is in the lift don't know why, but don't work
I saw that source earlier and tried modifying it to fit my needs, but that would not work either.. Thanks Though!
Your answer
![](https://koobas.hobune.stream/wayback/20220613075407im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
OnTriggerEnter not being called with multiple colliders 1 Answer
Make a simple tree 1 Answer
Do Child Objects Trigger Parent Objects? 1 Answer