You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
public class HorizontalSpriteLayoutGroup : MonoBehaviour
{
public GameObject prefab;
public int number = 5;
private void Start()
{
var size = transform.localScale;
float dividedSize = size.x/number;
float firstPos = (size.x)/2-(dividedSize/2);
for (int i = 0; i < number; i++)
{
var spawn = Instantiate(prefab, transform.position - new Vector3(firstPos,0,0), Quaternion.identity);
spawn.transform.position += new Vector3(i*dividedSize,0,0);
var spawnscale = prefab.transform.localScale;
spawnscale.x = dividedSize;
spawnscale.y = size.y;
spawn.transform.localScale = spawnscale;
}
}
}
VerticalSpriteLayoutGroup
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
public class VerticalSpriteLayoutGroup : MonoBehaviour
{
public GameObject prefab;
public int number = 5;
private void Start()
{
var size = transform.localScale;
float dividedSize = size.y/number;
float firstPos = (size.y)/2-(dividedSize/2);
for (int i = 0; i < number; i++)
{
var spawn = Instantiate(prefab, transform.position - new Vector3(0,firstPos,0), Quaternion.identity);
spawn.transform.position += new Vector3(0,i*dividedSize,0);
var spawnscale = prefab.transform.localScale;
spawnscale.y = dividedSize;
spawnscale.x = size.x;
spawn.transform.localScale = spawnscale;
}
}
}
GridSpriteLayout
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
public class GridSpriteLayout : MonoBehaviour
{
[SerializeField]
private Vector2Int gridSize;
public HorizontalSpriteLayoutGroup horizontalSpriteLayoutGroup;
public VerticalSpriteLayoutGroup verticalSpriteLayoutGroup;
private void Awake()
{
horizontalSpriteLayoutGroup.number = gridSize.x;
verticalSpriteLayoutGroup.number = gridSize.y;
}
}