左键按下给TEXT列表随机生成数字 抬起左键该TEXT 排序并且 给所在层级2以上的TEXT 更改颜色
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
using Random = UnityEngine.Random;
public class No06_Do : MonoBehaviour
{
public Text[] MyTexts;
void Start()
{
MyTexts = transform.GetComponentsInChildren<Text>();
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
MyTexts.ToList().ForEach(x => x.text = Random.Range(0, 20).ToString());
MyTexts.ToList().ForEach(x => x.color = Color.black);
}
if (Input.GetMouseButtonUp(0))
{
MyTexts.ToList().OrderBy(myd => int.Parse(myd.text)).ToList().ForEach(x => x.transform.SetAsLastSibling());
MyTexts.ToList().Where(item => item.transform.GetSiblingIndex() > 2 && item.transform.GetSiblingIndex() < MyTexts.Length).ToList().ForEach(x => x.color = Color.yellow);
//var numQuery = from num in MyTexts
// where (num.transform.GetSiblingIndex() >2)
// select num as Text;
//numQuery.ToList().ForEach(x=> Debug.Log(x.text));
}
}
}