代码修改子物体的顺序

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ChangeSort : MonoBehaviour
{

    public int max = 0;
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            max++;
            if (max >= 4)
            {
                max = 0;
            }
            transform.GetChild(max).SetAsFirstSibling();
        }
        if (Input.GetKeyDown(KeyCode.A))
        {
            max++;
            if (max >= 4)
            {
                max = 0;
            }
            transform.GetChild(max).SetAsLastSibling();
        }
        if (Input.GetKeyDown(KeyCode.S))
        {
            max++;
            if (max >= 4)
            {
                max = 0;
            }
            transform.GetChild(max).SetSiblingIndex(2);
        }
    }
}

猜你喜欢

转载自blog.csdn.net/gaojinjingg/article/details/82856481
今日推荐