title: How can I create a custom inspector guilayout.toggle?
body: <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEditor;
  using UnityEngine;
  
  [CustomEditor(typeof(Control))]
  public class ControlEditor : Editor
  {
      public override void OnInspectorGUI()
      {
          base.OnInspectorGUI();
  
          Control control = (Control)target;
  
          if (GUILayout.Toggle(control.isControl, "Control"))
          {
              control.ToControl();
          }
      }
  }
  </code></pre>
  
  <p>And</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class Control : MonoBehaviour
  {
      public Rigidbody rigidbody;
      public bool isControl = false;
  
      // Start is called before the first frame update
      void Start()
      {
  
      }
  
      public void ToControl()
      {
          if(isControl == false)
          {
  
          }
          else
          {
              Destroy(rigidbody);
          }
      }
  }
  </code></pre>
  
  <p>What I want to do is a guilayout.toggle or a button and to be able to destroy and to add a Rigidbody to the gameobject the Control script will be on.</p>
  
  <p>How do I create back add the Rigidbody to the gameobject ?</p>
  
  <p>And how do I use the isControl flag ? The idea is to use the guilayout.toggle in the editor script.</p>
  
  <p>I want to destroy or add a new rigidbody while the game is running ! But using a guilayout.toggle or button in the inspector. </p>