Last active
June 7, 2024 09:38
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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