条件:不能放在Editor下,需要挂载到物体身上。

    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. [ExecuteInEditMode]
    5. public class TestGame : MonoBehaviour
    6. {
    7. private void OnGUI()
    8. {
    9. if( GUILayout.Button("test1", GUILayout.Width(100)))
    10. {
    11. Debug.Log("test1");
    12. }
    13. }
    14. }

    image.png