- Home /
How can I set position of a GUI.Button in Inspector ?
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
[CustomEditor(typeof(ConversationTrigger))]
public class ConversationTriggerEditor : Editor
{
private ConversationTrigger conversationtrigger;
private void OnEnable()
{
conversationtrigger = FindObjectOfType<ConversationTrigger>();
}
public override void OnInspectorGUI()
{
DrawDefaultInspector();
if(GUI.Button(new Rect(0.1f,0.5f,0.1f,0.1f), "Add new item"))
{
conversationtrigger.conversations.Add(new Conversation());
}
if (GUILayout.Button("Save Conversations"))
{
conversationtrigger.SaveConversations();
}
if (GUILayout.Button("Load Conversations"))
{
Undo.RecordObject(conversationtrigger, "Loaded conversations from JSON");
conversationtrigger.LoadConversations();
}
}
}
I tried this line :
if(GUI.Button(new Rect(0.1f,0.5f,0.1f,0.1f), "Add new item"))
But that make the button vanished like deleted. If I'm using GUILayout.Button I will see the button but then I can't set the button position so I'm using GUI.Button.
This is a screenshot of the Inspector :

I want to position the button "Add new item" before the Canvas and always after the last conversation item in this case the Locked Room and if I will add a new item the button should be stay after the new added item and before the Canvas.
I guess this values of the Rect are wrong making the button to be positioned out of the window.
Your answer
Follow this Question
Related Questions
How can i check/wait until the gameobject will end the rotation ? 1 Answer
How can I add a speed factor to the script ? 0 Answers
How can i check and fire an event when the user look at specific object ? 0 Answers
Sorting a list based of a variable 1 Answer
How can i List objects by name but also in small text or big text or any kind ? 1 Answer