- Home /
Help ! : Move First Prefab Index of specific Panel, to Last index of another Specific panel ?
10 Panels, each with 4 index(1 column), 8 are filled panels and two are empty , I wrote one script to access each index for each panel, Question how can I move first index prefab of a specific panel, to the last empty index of another specific panel ? using System.Collections; using System.Collections.Generic; using UnityEngine;
public class FindingReferenceofAnObject : MonoBehaviour { // Start is called before the first frame update public GameObject ObjectToFind1; public GameObject ObjectToFind2; public GameObject ObjectToFind3; public GameObject ObjectToFind4; void Start() {
ObjectToFind1 = transform.GetChild(0).gameObject;
ObjectToFind2= transform.GetChild(1).gameObject;
ObjectToFind3 = transform.GetChild(2).gameObject;
ObjectToFind4 = transform.GetChild(3).gameObject;
// how do I transform ?
}
// Update is called once per frame
void Update()
{
}
}
Answer by privatecontractor · Jan 24 at 07:57 PM
Hi @Aberreda,
Not sure what is whole scenario, but to move them according to your question will need to call transform.SetParent(newColumn.transform) on Prefab you willing to move (the first prefab in first column...). When transform have parent... we could also set this transform Sibling Index in order to change its position in hierarchy.
But hierarchy need to sort your transform in columns after each change.... you could use Vertical Layout Group for this (atached for Each Column)... just setup right Child Alignment and spacing / padding
On the other side maybe better solution will be just creating lots of buttons (able to change colours) and moving around some values (let's say that each colour could be represented by int: empty = 0, green = 1, blue = 2, etc...) so when you click you could just move values, and make slot reacts to it, with displaying value assigned to colour, and button activation etc...
Hope will help.