Cute_demon_attacks/meng_yao/Assets/Epic Toon FX/Materials/testzzz.cs

50 lines
1.3 KiB
C#
Raw Normal View History

2024-12-24 17:40:42 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class testzzz : MonoBehaviour
{
private GameObject[] gameObjects;
// Start is called before the first frame update
void Start()
{
}
public void UpdateNodeList()
{
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>о<EFBFBD><D0BE><EFBFBD> SpriteRenderer <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GameObject
List<GameObject> gameObjectsList = new List<GameObject>();
foreach (Transform child in transform)
{
SpriteRenderer renderer = child.GetComponent<SpriteRenderer>();
if (renderer != null)
{
gameObjectsList.Add(child.gameObject);
}
}
// <20><><EFBFBD><EFBFBD> y <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
gameObjectsList.Sort((a, b) => a.transform.position.y.CompareTo(b.transform.position.y));
// <20><><EFBFBD><EFBFBD> sortingOrder <20><><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (int i = 0; i < gameObjectsList.Count; i++)
{
Debug.Log(gameObjectsList[i].name);
SpriteRenderer renderer = gameObjectsList[i].GetComponent<SpriteRenderer>();
if (renderer != null)
{
renderer.sortingOrder = gameObjectsList.Count - i;
}
}
}
private void FixedUpdate()
{
UpdateNodeList();
}
// Update is called once per frame
void Update()
{
}
}