Attach two different objects on the same Rotation values

Hello to everyone!

I have a House Object and i want to place it on a Plane. For example i want to move the plane in a certain position and rotation and the House must follow -by script- those values (position & rotation).

First i create my House on javascript, which is a parent with its children components on a script:

//create objects
var House : GameObject;
//Random ranges between X, Y coordinates
public var RandX:float; 
public var RandZ:float; 
//MAIN function
public function mainDO() {
MainBuilding(RandX, RandZ); //parent
Windows(RandX, RandZ); //child
//.... more children
public function MainBuilding(RandX, RandZ){
	House=  GameObject.CreatePrimitive(PrimitiveType.Cube); 
	House.transform.position = Vector3(this.RandX, 3.985427, this.RandZ); = "House";
	House.transform.localScale.x = 12.90037;
	House.transform.localScale.y = 7.680003; 
	House.transform.localScale.z = 6.561959;
}//end function

public function Windows(RandX, RandZ){
Window.transform.parent = House.transform; //parenting
}//end function

Now, on a different script, called plane, i do this:

public var h: House; 

public var pln: GameObject; //create plane object
pln = GameObject.Find("Plane_lvl_4");//the plane object there is already on the scene like a mesh which the generated House object from the script will be attached on this plane on a certain position and rotation too i give below. 

    function Start() {
    	h = gameObject.AddComponent("House");
    	h.RandX = pln.transform.position.x;
    	h.RandZ = pln.transform.position.z;
    	h.transform.rotation = pln.transform.rotation;
    }//end function start

Both scripts work fine, my house is been generated on the position of the plane, BUT… rotation doesn’t work at all here and i can’t figure out why.
Anyone to help?


Great script, and well done for the effort that you have put into it!:wink: What if you just make the house a child of the plane or vica versa, and if worst comes to worst then use an animation on the plane…

Don’t see why it shouldn’t be working though :confused:

In which part of the script are you telling the house to rotate, though?:slight_smile:


h.transform = pln.transform; on that i have a compile error saying: Property ‘UnityEngine.Component.transform’ is read only.

I just want to align the rotation of the house with the rotation of the plane.

It displays the message log with the rotation coordinates. That means it’s kinda work but not as i expected to see it, cause the house hasn’t been rotated according to the plane rotation.

Thanks for ur help anyway.
I know the above code seems right but it feels i 'm missing something… :frowning:

@PhsycoticRaptor :

I suppose to say that on the plane script, i’m not using rotation on House cause i don’t want to rotate anything there (on house script). All i need is to rotate the plane for example y=90 degrees and then the house object “can see” that value and get rotation equal to y=90 degrees. that’s what i try on the plane script. If there’s anything else u want to suggest go ahead, i’m listening. Thank you too.