Calculating an object's bounds...

Hello. I am trying to spawn an object in such a way so that the object that is spawned is edge to edge with the object that did the spawning. They both have box colliders attached to them but they are different lengths, I am trying to have them be right next to one another (just as if I had put them there manually). I created this script to do the job, but it is not working (the object is spawned at a seemingly random position).


var MyPrefab : GameObject;

function Update    (){
	transform.Translate(Vector3.right * Time.deltaTime * -1);

function OnTriggerExit (other : Collider) {
	Instantiate (MyPrefab,Vector3(transform.position.x+collider.bounds.size.x+MyPrefab.collider.bounds.size.x, transform.position.y, transform.position.z), Quaternion.identity);

Use bounds.extents instead of bounds.size. Since the object position is usually at the centre of the object, you should use only half of the size for each collider (extents is exactly that).