Introducci贸n a las herramientas de desarrollo para videojuegos
Introducci贸n
Qu茅 son las herramientas de desarrollo
Herramientas m谩s comunes en el mundo del desarrollo de videojuegos
Dibujando en el editor
Sistema IMGUI y Ciclo de vida de Editor
Controles: creando un bot贸n
Creaci贸n de toolbar y gui
Gizmos
Handles
Pr谩cticando en el editor
Shortcuts 煤tiles del editor
Context Menus
Menu Item
Herramientas de Editor
Attributes y Property drawers
Iniciando nuestro custom Editor
Serialized properties
Optimizando nuestro custom editor
Guardar y cargar data de herramientas: json, scriptable objects, txt y csv
Encontrar assets para editor window
Editor windows: mostrando datos en el editor
Editor windows: agregando funcionalidades
Cierre del curso
Cierre del curso
You don't have access to this class
Keep learning! Join and start boosting your career
Getting into the world of Unity development can be exciting and challenging at the same time. One of the most important aspects to master is the use of controls. These are fundamental for drawing and creating interactive interfaces. There are several types that can be used, such as buttons, sliders and text boxes, and the way you position them can vary. Learning how to use these controls correctly will allow you to create more effective and fluid user experiences.
Unity uses a system of rectangles, known as a Rect, to define the position and size of on-screen controls. Unlike traditional systems where the origin (0,0) is in the lower left corner, in Unity the origin is in the upper left corner.
This system measures distances in pixels, which may require some manual adjustments to correctly position your elements on screen. Fortunately, Unity offers several useful features for working with Rects, such as locating the center and detecting collisions with other rectangles, making the design much more intuitive.
When working in Unity, you will face two main types of interfaces when developing GUIs:
Manual GUI: This type of interface requires you to manually define the position, size, height and width of each element. Although it offers more control over the design, it also requires more time and effort.
GUI Layout: Unlike the manual GUI, the GUI layout is an automatic system that places the controls for you. It is a more efficient way to work, but at the cost of having less control over the exact layout.
Both systems have their pros and cons. While manual intervention gives you more precision, the automatic system speeds up the design process and allows for faster changes.
Creating a button in Unity is a great way to start understanding the implementation of GUI controls. Here's how to do it:
using UnityEngine;
public class GUIExamples : MonoBehaviour{ void OnGUI() { // Define the position and size of the Rect for the button Rect buttonRect = new Rect(0, 0, 100, 50);
// Create and display the button if (GUI.Button(buttonRect, "Press")) { Debug.Log("Button pressed"); } } }}
true
, triggering any action within its if
block.The GUIContent
in Unity allows you to define the text and image to be displayed in a control. You can, for example, add an image and text at the same time, maximizing the visual richness of your interface.
To give functionality to a button, you must use the boolean value returned by the GUI.Button
method each time it is pressed:
// Inside the OnGUI() methodif (GUI.Button(new Rect(0, 0, 100, 50), "Hello Platzi")){ Debug.Log("Button pressed");}
This simple structure allows you to implement different actions that will be executed when the button is pressed, such as restarting a game, opening a new menu or updating information on the screen.
Don't forget that practice is essential to understand how to design and program effective interfaces in Unity. Experiment with different types of controls and systems to find the one that best suits your needs, keep learning and improving your game development skills!
Contributions 0
Questions 0
Want to see more contributions, questions and answers from the community?