Lock rotation of an instantiated object to another

I am instanciating objects using this script.

`var prefab : GameObject;

function Update() {

 var position = Random.onUnitSphere*30.5000;

 var spawnPreferences = Instantiate(prefab, position, Quaternion.identity);

}`

How would I go about locking the rotation of the spawned object to another?

Thanks

Childing will lock pos+rot. If you want the second object to move freely but only copy rotation, you have to do it yourself, every frame. For example, on spawn, set the rotateParent and give the new object something like this:

public Transform rotateParent; // not the actual parent. Hand-set at spawn

void Update() { transform.rotation = rotateParent.rotation; }

If the spawned object is a rigidbody, can safely lock rotations (tells physics only not to spin – code can still do it.)