- Home /
How to transform parent object from child?
I have multiple parent objects(all are same) with same name. I want to transform the object(parent) when player enters the trigger(child object). With the code I have I can not move its own parent(as all have the same name). I want only its parent to be transformed.
private var start : Vector3;
private var end : Vector3;
private var moveb : boolean = false;
var duration : float = 1.0;
private var startTime : float;
function Update () {
if(moveb==true){
Debug.Log("got it");
GameObject.Find("Box1").transform.position = Vector3.Lerp(start, end, (Time.time - startTime) / duration);
if(GameObject.Find("Box1").transform.position==end){
moveb=false;
}
}
}
function OnTriggerEnter(other : Collider){
start = GameObject.Find("Box1").transform.position;
startTime = Time.time;
end = start + Vector3(0,0,10);
moveb=true;
}
Instead of "GameObject.Find("Box1")" which makes some other object to move, I want something that transforms only its parent.
Comment
Best Answer
Answer by CodeMasterMike · Dec 11, 2012 at 03:02 PM
This snippet takes the colliding object, and gets the Transform from its parent.
Transform parentTransform = other.gameObject.transform.parent.transform;
Your answer
![](https://koobas.hobune.stream/wayback/20220613085255im_/https://answers.unity.com/themes/thub/images/avi.jpg)