Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Get your own script by dragging a gameobject to a field of a custom window

Discussion in 'Scripting' started by ftejada, May 14, 2023.

  1. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    I am creating a custom window in Unity.
    And I want the window to have fields to be able to drag gameobjects from the scene, to get a script of my own that I have created and it is attached to the gameobject that I want to drag into the field of the custom window.

    I tried with: "myScript = EditorGUILayout.ObjectField(myScript, typeof(myScript), false) as myScript;"

    But it seems that it only works for dragging prefabs to the window fields, and not scene objects that have this script.

    How can I get what I need? Is what I want possible?

    Greetings
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,769
    Take a look at the docs and what the boolean you're passing
    false
    into does.
     
    Bunny83, Yuchen_Chang and ftejada like this.
  3. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    Thanks!!!