Hello. I have been working on creating a grid menu which holds all the cards in a players deck, like in the game Slay the Spire
All the cards (Instantiated and copied from the original deck) will be laid out in the grid layout group in a scroll view on a panel in my main UI canvas, which I will then activate to show the player when they click on the button, however, no matter what I try the cards move no where and do nothing.
I have tried:
Other layout groups
On-Runtime Instantiation and In-Editor adding
I am trying my best to avoid doing it by hand cause it would be a hassle, however, this is apparently a large hassle in and of itself.
Here is my Dynamic object adder, where deckManager has the cards, a card is a game object with a canvas so as to more easily work with prefabs, and content, is the Content object in a ScrollView object.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
public class DrawMenuDisplay : MonoBehaviour
{
public Transform content;
public DeckManager deckManager;
// Start is called before the first frame update
void Awake()
{
List<Card> listCopy = new List<Card>();
foreach(Card card in deckManager.deck) {
listCopy.Add(card);
}
int n = listCopy.Count;
for(int i = 0; i < n; i++) {
int r = i + Random.Range(0, n - i);
Card c = listCopy[i];
listCopy[i] = listCopy[r];
listCopy[r] = c;
}
foreach (Card card in listCopy) {
Card newCard = Instantiate(card, content.transform);
newCard.transform.localScale = new Vector3(25, 25, 1);
newCard.gameObject.SetActive(true);
}
}
void OnDisable() {
foreach (Transform child in transform) {
if(child.CompareTag("Card")) {
Destroy(child);
}
}
}
}
Here is a snapshot of what I have been beating my head against, highlighting the content object with the layout group.
This screenshot after the class above takes effect. The menu UI goes over the UI underneath it, and the created Cards can be seen hiding in the top left corner. If there is any other information needed. I will be happy to provide.