代码修改子物体的顺序

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);
        }
    }
}

 

你可能感兴趣的:(unity入门)