This video will be about how to achieve communication between Scripts in programming, specifically in development with Unity.
Specifically what we want is to access the fields and methods (ie variables, objects and functions), which are within a script, from a second script.
To give an example we will solve a simple problem that consists of a Script that implements a health system that has an integer that moves between 0 and a maximum value and we have functions that hurt it and regenerate it, the goal is that the user interface (which is controlled from a second Script) shows the health value constantly
0:00 - Introduction
0:49 - What are we going to do?
1:32 - Example: Communication between Health System and User Interface
2:03 - It is not a good idea to program everything in one single script
2:42 - Dividing responsibilities is a better alternative
3:47 - Moving on to Unity's implementation of communication between Scripts
3:51 - Brief explanation of the example of the article on communication between Scripts
4:33 - We begin to implement the example proposed in the video
4:48 - How the user interface will be
5:02 - Creation of the user interface
6:53 - Object Player and creation of "HealthSystem" and "UserInterface" scripts
7:48 - Programming the User Interface script. Definition of fields
8:30 - Programming of the health system script. Definition of fields and methods
9:19 - Methods of damage and regeneration to decrease or increase health
9:52 - No hard coding!
10:25 - Getter method for reading current player health
10:50 - How are we going to deal with the problem?
11:28 - Pros and cons of the two proposed alternatives
12:15 - Programming of the first alternative: The graphic interface asks the health system how much life the player has
12:17 - Distinction between class and object when in a script
12:56 - Finding the reference of an object
14:03 - User interface update method, communication between user interface scripts and health system
14:33 - Point operator to access public fields and methods in other scripts
15:29 - Assigning Scripts and settings in the inspector for the test run
16:11 - Assignment of functions to buttons in Unity
17:03 - Test run of the first alternative
17:36 - Implementation of the second alternative: The health system, when there is a change in the player's life, alerts the graphic interface to change its value
18:19 - Define and obtain the reference of the Graphical Interface object from the Health System Script
19:16 - User interface methods
19:48 - Communication between health system scripts and graphical interface
20:21 - Adjustments in the inspector for the second alternative
20:56 - Test run. Bug due to uninitialized User Interface
21:48 - Conclusion
- Article about Communication between Scripts in Unity in the following Link:https://gamedevtraum.com/en...
-Video about CLASSES in PROGRAMMINGhttps://www.youtube.com/wat...
The video about Classes in Porgramming serves to understand a little more about Scripting and Object-Oriented Programming.
-Article on CLASSES in PROGRAMMING (theory and practice)https://gamedevtraum.com/en...
- Downloadable solutions for Unity here:https://gamedevtraum.com/en...
These solutions generally come as a package from Unity so you download them and import them into your project
- 3D models here (use the download section of the menu to navigate):https://gamedevtraum.com/en...
-Rock Mix to Program lml o.o lmlhttps://www.youtube.com/wat...
Subscribe if you haven't already! :D