Revers Object Transfrom using an array problem in UI !!
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class RandomObj : MonoBehaviour {
public GameObject[] objs;
private GameObject tmp;
void Start(){
objs = new GameObject[this.gameObject.transform.childCount];
for (int i = 0; i < this.gameObject.transform.childCount; i++) {
objs[i] = this.gameObject.transform.GetChild(i).gameObject;
}
ReversArray ();
}
void ReversArray(){
int n = objs.Length;
for (int i = 0; i < n / 2; i++) {
int j = n - i -1;
tmp = objs[i];
objs[i] = objs[j];
objs[j] = tmp;
var firstAndThelast = Instantiate(objs[i], new Vector3(objs[j].transform.position.x,objs[j].transform.position.y , -2),Quaternion.identity);
var MiddleAndBeforLast = Instantiate(objs[j], new Vector3(objs[i].transform.position.x,objs[i].transform.position.y , -2),Quaternion.identity);
firstAndThelast.transform.SetParent(gameObject.transform);
}
}
} / this code will revers object transform it's work find with object but with UI , i need to setPrarent to Canvas when instance so just 2 object parented but other's don't why ??? /
Comment
Your answer
Follow this Question
Related Questions
Why Does Prefab Loose UI elements on Scene Change 0 Answers
Use Gameobject.Find function on an object in a new scene, after loading that scene. 1 Answer
Move gameObject on UI Button Press 2 Answers
Temple Run and Subway Surfers Game Over Implementation? 0 Answers
Object looses Inspector properties When Scene returns 1 Answer