Skip to content

Instantly share code, notes, and snippets.

@koster
Last active June 7, 2024 09:38
Show Gist options
  • Save koster/9344ab0030839616c4b002c7136551dd to your computer and use it in GitHub Desktop.
Save koster/9344ab0030839616c4b002c7136551dd to your computer and use it in GitHub Desktop.
A component that aligns stuff in a straight line, pretty straightforward. Put this on a transform and add children to it, adjust width.
using UnityEngine;
[ExecuteInEditMode]
public class CardSetAlign : MonoBehaviour
{
public float width = 1f;
void Update()
{
var count = transform.childCount;
var centerOffset = width * (count * 0.5f - 0.5f);
for (var i = 0; i < count; i++)
{
transform.GetChild(i).localPosition = new Vector3(i * width - centerOffset, 0, 0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment