2D game. How to place the second object on x at a distance equal to half the size of the firstobject?. Use Scripting
If the scale is normal (I mean by that : when the object size == 1, it is one unit high and large in world space).
“Object2.transform.position = Object1.transform.position + Vector3.right * (Object1.localscale.x *1.5f + Object2.localscale.x *0.5f)”
(it should work, even if the two objects have different sizes)
What hlw said is correct. But if you want to eliminate the size factor, this code will help you:
public SpriteRenderer object1, object2;
void Start()
{
float object1_size = object1.sprite.bounds.size.x * object1.transform.localScale.x;
object2.transform.localPosition = object1.transform.localPosition + new Vector3(object1_size * 1.5f, 0);
}
1 Like
