스페이스바 누름 구현
This commit is contained in:
29
Assets/Scripts/Alignment.cs
Normal file
29
Assets/Scripts/Alignment.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class NewMonoBehaviourScript : MonoBehaviour
|
||||
{
|
||||
|
||||
private GridLayoutGroup _gridLayoutGroup;
|
||||
private RectTransform _rectTransform;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
_gridLayoutGroup = GetComponent<GridLayoutGroup>();
|
||||
_rectTransform = GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
var max =
|
||||
(_rectTransform.rect.width / (_gridLayoutGroup.cellSize.x+_gridLayoutGroup.spacing.x)) *
|
||||
(_rectTransform.rect.height / _gridLayoutGroup.cellSize.y+_gridLayoutGroup.spacing.y);
|
||||
var current = transform.childCount;
|
||||
|
||||
if (current / max >= 0.8f)
|
||||
{
|
||||
_gridLayoutGroup.cellSize = new Vector2(_gridLayoutGroup.cellSize.x * 0.9f, _gridLayoutGroup.cellSize.y * 0.9f);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user