1. 程式人生 > >程式碼修改子物體的順序

程式碼修改子物體的順序

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