Introduction to Texturing in Blender

Texturing a 3D model is a crucial step that brings your design to life. It involves adding colors and intricate details that enhance the visual appeal of your work. In this guide, we will explore how to texture a 3D model in Blender using images as a primary resource for colors and textures.

This is how you apply textures to 3D models in Blender explained in video:




Preparing Your Model for Texturing

Before diving into the texturing process, it’s essential to make sure your 3D model is properly prepared. This includes ensuring that your model’s UV mapping is correctly set up.

UV mapping is a process that translates the 3D surface of your model into a 2D surface, allowing you to apply textures accurately.

You can access the UV Editing workspace in Blender to adjust and optimize the UV layout.

Creating a UV Map for texturing your 3D model – Step-by-step

To quickly create a UV Map for your 3D model you can follow this steps:

  • Select your object.
  • Go into edit mode
  • Select all the vertices by pressing A a couple times
  • Press U to bring the UV Mapping contextual menu
  • Choose the option “Smart UV Project“, that function usually have nice results and at this point you are ready to apply textures to your 3D model.
smart uv project function to create a uv map to apply textures to models in Blender
UV Mapping contextual menu. Smart UV Project function

Applying Textures and Colors

With your UV map in place, you can start applying textures. Blender allows you to use image textures that can be imported into your project. To do this, navigate to the Shader Editor and create a new material. Add an Image Texture node and load the image you wish to apply. Connecting this node to the Base Color of your material will display the image on your model. Adjust the mapping settings in the Image Texture node to fit your model correctly.

As you work on how to texture a 3D model in Blender, remember to tweak various settings such as scaling, rotation, and placement to get the desired look. Utilizing additional nodes for bumps and specularity can also enhance the realism of your textures.

You have reach the end of the article, if it was useful consider subscribing to the channel!

Introduction to Proportional Editing in Blender

Bending 3D models in Blender can transform your designs into dynamic, organic shapes. One of the most effective tools for achieving this is the Proportional Editing feature. This tool allows you to manipulate vertices, edges, and faces while maintaining a smooth transition across nearby elements. It’s essential for achieving that natural look in your models.

Activating Proportional Editing

To start bending your model, you first need to activate Proportional Editing. You can do this easily by selecting your object, entering Edit Mode (press Tab), and then clicking the circle icon in the toolbar or simply pressing the ‘O’ key. A highlighted circle will appear around your selected vertex, indicating the area of influence you can manipulate. This circle can be adjusted using your mouse wheel, increasing or decreasing the size of the affected area.

There is a video tutorial on this topic:




How to Bend Your Model

With Proportional Editing activated, it’s time to bend your model. Select the vertex you want to move and drag it to your desired location. As you move the vertex, you’ll notice that surrounding vertices will also adjust based on the influence of the Proportional Editing tool, you can use the mousewheel while moving the element to modify the influence of the proportional editing tool. This tool is not limited to one vertex, you can select multiple vertices, edges or faces and the bending will be calculated using all those elements.

This technique is ideal for creating curves or bending areas of your model without compromising the overall shape.

If you need to achieve more complex curves, consider experimenting with the different falloff settings available (such as Smooth, Sphere, or Root). Each will provide a unique effect on how the surrounding geometry interacts as you make your adjustments. This versatility is key in getting the precise look you want.

Conclusion

In conclusion, mastering the Proportional Editing tool in Blender offers you incredible flexibility in bending 3D models. With practice, you can create intricate and engaging designs that elevate your projects. Start experimenting with this powerful tool today, and watch your creative possibilities expand.

You have reach the end of the article, if it was useful consider subscribing to the channel!

Image 1. Game window with the Unity console attached at the bottom. Screenshot take from the survival game I’m developing in Unity

Understanding Unity Console Basics

In Unity, the Console window is an essential tool for developers. It allows you to view logs, warnings, and error messages generated by your code. Writing messages to the console can be incredibly helpful for debugging and tracking the flow of your application.

Most useful console instruction – Debug.Log

One of the simplest ways to write something in the console is by using the Debug.Log method. This method enables you to display messages in the console. To use it, simply call Debug.Log("Your message here"); inside any function in your script. For example:

void Start() {

Debug.Log(“Game has started!”);

}



How to WRITE messages in the CONSOLE in Unity

Writing the Debug.Log instruction by itselft it won’t write your message in console, you need to ensure that the function where you send the console message is executed, for this to happen, certain conditions must be met:

  • The script with the function in which you send the console message must be attached to a GameObject in the scene.
  • The GameObject that has the script assigned must be active at some point of the lifetime of your application.
  • Console logs must be enabled, look for the icons at the top right of the Console window.

Logging Different Message Types

In addition to Debug.Log, Unity offers other logging methods such as Debug.LogWarning and Debug.LogError. These methods are useful for indicating potential issues or errors in your code:

Debug.LogWarning("This is a warning!");
Debug.LogError("This is an error!");

By using these different logging methods, you can categorize messages effectively, making it easier to identify issues within your project.

In summary, writing output to the console in Unity is straightforward with the use of the Debug.Log methods. Whether you’re logging regular messages, warnings, or errors, these tools provide vital insights into your game’s running state.

You have reach the end of the article, if it was useful consider subscribing to the channel!



In this artcile we see how to show the current system time in Unity in a text from the user interface.

This could be useful for example to have a VR smartwatch and display the system time in a world space Canvas attached to that smartwatch.

This solution is in the “GDT Solutions for Unity” GitHub repository

There is a video tutorial on this topic:




Procedure to create a Script that controls a digital clock

This article is about how we can read the system time in Unity and showing it on a text in the Canvas

First of all let’s create a new script and also create an empty GameObject to assign the script, as shown in the following images

Image 1. We create a new script
Image 2. We create a new empty GameObject
Image 3. We assign the script to the empty GameObject

Inside the script declare the TMPro namespace and define a TMP_Text variable, call it for example “text_currentTime“, as shown in the lines 3 and 8 of the following image.

Image 4

In the hierarchy, inside your Canvas, create a new Text Mesh Pro object. If you don’t have a Canvas Unity will create one for you.

Image 5
Image 6

In case you need it, here is a video on how to work with Text Mesh PRO, you may want to check it, if it’s the first time using it.

Select the GameObject object that has the script, take the Text Mesh Pro object and drop it in the field in the inspector that corresponds to the TMP_Text variable we defined. By doing this, now we have the reference of the text object in our script and we can modify it by code.

Image 7: Text Mesh PRO text component was assigned to the TMP_Text variable field in the inspector.


Inside our script, let’s add the “System” namespace and define a “DateTime” type variable, call it for example “currentTime“.

Inside Update we are gonna assign to that variable, the following instruction (pay attention to uppercase characters):

currentTime = DateTime.Now;

We can use this currentTime variable to get information about the current time, for example which hour it is, the current minute and the current second. So let’s define a couple local int variables to temporarily assign those values.

int hour = currentTime.Hour;
int minute = currentTime.Minute;
int second = currentTime.Second;

Now that we have all the information we need, we can show the system time in our Unity game in the user interface using the TMP_Text variable we defined, and we can do so in the following way:

text_currentTime.text = hour.ToString(“00″)+”:”+minute.ToString(“00”)+”:”+second.ToString(“00”);

Image 8. Update method in Unity to display system time on a Canvas text.

Hit play and you should be seeing that it is working.

Adapt this solution to create a VR smartwatch in Unity

This solutions works exactly the same if you want to display the current time on a VR smartwatch, the difference is that you probably will need to configure the Canvas as World Space, assign your VR camera in the canvas field in the inspector and attach the Canvas object as a child of the Hand anchor of your VR controller.

You have reach the end of the article, if it was useful consider subscribing to the channel!

In this article we see how to draw the outline on the edges of 3D models in Blender, using the Freestyle tool within the Render Properties.

You can configure the thickness of the outline and apply modifiers to it, you can also choose the color of the outline or use a modifier, for example a random noise generetor that allows you to randomly choose between different colors.

There is a video tutorial on this topic:




Let’s start with a basic 3D model with a camera that is pointing towards it, if we press F12 we will get a render of the scene from the prespective of our camera, as we can see in the following two images.

Starting point with a basic 3D model and a camera
Image result after pressing F12

Now, we can easily add an outline to our 3D model going to the render Properties by activating the freestyle checkbox.

Access to the render properties.
Freestyle checkbox inside render properties that enables the Outline.

If we make a render again we will see that the outline is being generated on the edges of our 3D model.

Render with the freestyle checkbox checked. An outline is drawed on the edges of the 3D model.

You can quickly modify the thickness of the outline using the thickness variable inside the Freestyle section:

And in the View Layer tab you will find several options to apply to the outline, for example you can where to draw the outline along with other parameters like color and effects.

For detailed information check the video above.

You have reach the end of the article, if it was useful consider subscribing to the channel!

In this article we see how to import a custom font in Unity and how to create the TMP Font Asset using the Font Asset Creator, this allows you to change the font style of a Text Mesh Pro text in Unity.

There is a video tutorial on this topic:




Which Font format to use in Unity

Fully supported formats for custom fonts and Text Mesh PRO are:

TrueType Fonts (.ttf)

OpenType Fonts (.otf)

Other Formats: While Text Mesh Pro does not directly support other formats like Web Open Font Format (.woff / .woff2), you can convert these into .ttf or .otf if needed before importing them into Unity.

Procedure to use custom fonts with Text Mesh PRO in Unity

First of all you will need to import the font files in your Unity project, you can do that by taking the font files and dragging to a folder inside Assets.

To use custom fonts with Text Mesh Pro you need to generate a font atlas, which is done through the Font Asset Creator in Unity.

This process involves creating a texture atlas with the characters from the font file, which is then used by Text Mesh Pro for rendering text smoothly at various sizes.

To generate the font atlas in Unity go to the Window tab, then to TextMesh Pro and then Font Asset Creator, as you can see in the following image.

In the Font Asset Creator window you have a field called “Source Font” where you can drag your font file.

Once you drag the font you click on “Generate Font Atlas”.

The process will take a momento, when it’s done you save the file in your project folder.

The resulting Asset is a file that you can drag and drop it in to the font field from any TextMesh PRO component in the inspector. That will apply the custom font to your text

Where to find Fonts to download

You can get Font files from different websites like DaFont or 1001Fonts.

You have reach the end of the article, if it was useful consider subscribing to the channel!

I’m currently developing a survival game using the Unity engine and Blender to create 3D models, along with other programs like Substance Painter for texturing, Photoshop for image edition and Audacity for audio.

The main platform will be Android and the idea is to release a playable prototype on the Play Store in this 2025 year.

#0 – Intro video

In this video I talk about the game project and scope.

#2 – How I work with 3D models

#3 – About random generation items and world objects

In this video I talk about the game project and scope.

Just had this problem, spend hours searching on forums and just found diagnostics but not actual solutions.

If you have an Adobe Software like Photoshop or if you have a friend that has it, you can get the LIBEAY32.dll file in a safe way, without having to download it from a website that you don’t know if you can trust.

Video showing the way I solved the problem:



You have reach the end of the article, if it was useful consider subscribing to the channel!

Using GitHub you can have your projects backed up on the cloud, collaborate with others or just access to your projects from different computers.

In this article we will see how to use GitHub desktop to clone a Unity project from a GitHub repository, it’s a super easy process that doesn’t require you to learn console commands, just make a few clicks on GitHub Desktop. When you clone a Unity project from GitHub you get the project files in the location you indicate, so you will also need to add that project in Unity HUB.

There is a video tutorial on this topic:




Clone a Unity project from a repository step-by-step

  • First of all you need to create a GitHub account.
  • Then you need to download GitHub Desktop, a software that allows you to easily work with Git without using console commands, which could be difficult to set up and learn how to use. With GitHub Desktop you will be able to perform most of basic Git operations and it’s a nice way to start.
  • Install GitHub desktop and log into the account created in the first step.
  • Find the link of a Unity project repository you want to clone. Here you have two of my repositories for testing:

GDT Solutions for Unity

In this repository you will find a collection of solutions like a drag-and-drop first person controller or how to change from one scene to another in Unity.

https://github.com/GameDevTraum/GDT-Solutions-for-Unity.git

Escape from the maze

The Unity project files of a mini game where you have to find a set of objects randombly hide inside a maze in order to get the key that opens the gate to escape from the maze.

https://github.com/GameDevTraum/GDT-Games—Escape-from-the-maze.git

  • Inside GitHub Desktop go to File > Clone Repository, select the URL tab and paste the link of the GitHub repository you want to clone.

  • Choose a folder where you want to store the project files, in my case I have a Unity folder where I have all my projects and I would use that folder because we are cloning a Unity repository, but you could choose any folder you want.
  • After the process is finished, we already have the files in the location we indicate and as you can see these files correspond to a Unity project, so for the next step let’s open Unity HUB and add a project from disk.
  • Select the folder of the project and press Add Project, so now you already have the project in your Unity HUB and you can open it to check the solutions.

How to keep a repository updated

I will be adding more solutions to the GDT Solutions for Unity repository and also keep this project updated with the latest Unity’s LTS version. So if you want to receive new solutions make sure to follow my GitHub account and also watch the repository.

To look for new updates go to GitHub desktop, make sure you are in the right repository, discard all unnecesary changes, click here to refresh and if a new Update is available just press “Pull” and wait to the process is finished.

Then go back to Unity and reload the scene if necesary, that way you could receive new solutions that I will be making from time to time.

You have reach the end of the article, if it was useful consider subscribing to the channel!

First of all, you don’t need to export the 3D model in Blender because you can perfectly work in Unity using the Blender files, you just need to take the blend file and all the textures aplied to the model, move all the files to a folder inside your project in Unity and then you can take the Blend file and drag it to the scene in Unity, doing that you can use the Blender models in Unity.

The textures of the 3D model could not be automatically applied when you do the previous step, so we will see how to apply the textures to the 3D model that was exported from Blender, but first let me suggest to check the following video in which I explain all the process in detail:


Apply the texture to the exported model

In your Unity project select the blend file and in the inspector go to the Materials section (leave the image for reference) and there you will find all the materials that you defined in Blender, to remap the materials you have two options, you either replace the materials from the 3D model with new materials created in Unity or you extract the materials present in the Blend file.

Remap the Blender materials with new materials created in Unity

  • Create a new material.
  • Drag the material to the material field in the inspector.
  • Click on apply to remap.
  • Drag the textures to the material and adjust parameters to get the result you need.
  • Repeat the previous steps for every material your model has.

Remap the Blender materials by extracting them from the 3D model

  • Unfold the Blend file to find all the materials defined in Blender.
  • Select all the materials, right click and choose “extract from prefab” (check image below).
  • Save those materials and that way Unity create all the materials for you and automatically remap to those materials.
  • Drag the textures to the material and adjust parameters to get the result you need.

You have reach the end of the article, if it was useful consider subscribing to the channel!

Introduction – Circuit and Ohm’s Law

The purpouse of this entry is to show a very simple example of application in Unity, an electrical circuit with a DC source connected to a resistor.

The DC source provides a constant voltage over time and the resistor is a passive electrical component that is characterized by offering resistance to the flow of electric current. When these two components are connected as shown in Figure 1, a current is established that will be proportional to the voltage and inversely proportional to the resistance, according to Ohm’s Law:

I = V / R

Fig.1: Electrical circuit with DC source and a resistor, the current flowing will be calculated by applying Ohm’s Law.

Screenshots of the program running

Figures 2 and 3 show the program running, the circuit diagram is a representative image, the three values on the right are the actual values of the system, the voltage and resistance are variable parameters that can be changed using the sliders at the bottom and the current is calculated as a result of these values.

Fig. 2: Screenshot of the program running, the sliders allow to modify the voltage and resistance values, the current is calculated by applying Ohm’s Law.
Fig. 3: Another snapshot of the program with other values.

Analysis of the Script that controls the system

The script responsible for controlling the system and displaying the information on the screen is analyzed below.

System variables

Figure 4 shows the variables defined in the Script, in lines 9, 10 and 11 we have some references for the Text components that are responsible for displaying the values in the graphical interface. To see in detail how to write texts on screen dynamically in Unity see this video.

Then, three float variables are defined for the voltage, resistance and current of the circuit (lines 13, 14 and 15).

Fig. 4: Script variables controlling the DC circuit simulator.

Start function, value update on the screen and Ohm’s Law calculation

In figure 5 there are three functions belonging to the system. Start is a function that Unity executes automatically after pressing the Play button and before the first frame of the application is displayed, within this function Ohm’s Law is applied with the initial values that are defined and the values are refreshed on screen, this occurs in the execution of the methods of lines 19 and 20 respectively.

The “RefreshValues” method is responsible for writing the voltage, resistance and current values to the Text components of the graphical interface.

The “ApplyOhmLaw” method performs the calculation of the current as a function of the voltage and the resistance, here you could have an indeterminacy if the resistance (the denominator) is null, if this happens there is no error at run time, but Unity detects this situation and solves it by assigning the value “Infinity”, which serves as an indicator that there is an indeterminacy.

Fig. 5: Script functions controlling the DC circuit simulator, initialization, Ohm’s Law and GUI update.

Functions for modifying values from the graphical interface

In order for the Sliders of the graphic interface to be able to modify values within a Script, they must do it through public methods, the methods shown in figure 6 fulfill this purpose, the top one allows to modify the voltage value and the bottom one the resistance value. Note that not only the values are modified but also Ohm’s Law is recalculated and the values are refreshed on the screen.

Fig. 6: Functions of the script that controls the DC circuit simulator, public methods that allow to modify the voltage and resistance values by manipulating the sliders of the graphical interface.

Introduction

In previous entries we saw how to define matrices in programming and load data into them, in this article we will see how to multiply two matrices using two-dimensional arrays.

Initial data

We will start from two matrices “A” and “B” with preloaded data and we will analyze a method that will multiply two matrices that are sent as parameter and returns the result matrix.

In figure 1 we see the declaration of two 2×2 matrices and the loading of their data, then in lines 27 and 28 we make the calls to the method that is in charge of multiplying the matrices that are sent as parameters and returning the resulting matrix.

Fig. 1: Declaration of two matrices A and B, data loading and execution of the function that multiplies two matrices passed as parameters.

Algorithm for multiplying matrices in programming

The product of matrices is not commutative, so it matters the order in which the matrices are multiplied. Let’s consider that matrix A is on the left and multiply it by matrix B which is on the right.

The procedure to multiply two matrices consists of multiplying each element of the i-th row of the left matrix by each element of the j-th column of the right matrix and then adding these products, the result of that sum will be the ij-element of the resulting matrix. Therefore, in order to carry out the product of matrices, the condition that the number of columns of the left matrix equals to the number of rows of the right matrix must be fulfilled.

The result of the multiplication of matrices A and B will be another matrix that will have a number of rows equal to the number of rows in A and a number of columns equal to the number of columns in B.

Algorithm analysis

Figure 2 shows the implementation of an algorithm that multiplies two matrices that are sent as parameters. First the result matrix is declared and the sizes of both matrices are read, this is done in lines 32 to 36.

Then we check if it is possible to multiply both matrices, if it is not possible the result will be null, otherwise we proceed to solve the product of matrices.

The resulting matrix structure is created with the corresponding number of rows and columns (see the description of the procedure above). Then the three nested for loops shown in figure 2 are used to determine the value of each resulting element.

Fig. 2: Algorithm that solves the multiplication of two matrices received as parameters and returns a matrix that is the result of the product of both matrices.

Introduction

In previous entries we saw how to define matrices in programming and load data into them, in this article we will see how to add and subtract two matrices using two-dimensional arrays.

To be able to add or subtract two matrices it is necessary that both have the same size, that is to say the same number of rows and the same number of columns, otherwise the operation cannot be solved. We will take this into account in our algorithm, at the time of performing the operation we will check that these conditions are met and if everything is correct the sum will be solved, otherwise the returned matrix will have a null value and this result can be used to make subsequent checks, for example if the resulting matrix is different from null we consider that the operation was successful.

Initial data

We will start from two matrices “A” and “B” with preloaded data and we will analyze a method that will perform the sum of two matrices that are sent as parameter and returns the result matrix.

In figure 1 we see the declaration of two 2×2 matrices and the loading of their data, then in lines 28, 29 and 30 we make the calls to the methods that will be in charge of adding, subtracting or making a linear combination between the matrices that are sent as parameter, those methods will return the resulting matrix.

Fig. 1: Declaration of two matrices A and B, data loading and execution of the methods that add, subtract and perform a linear combination of both matrices.

Algorithm to add two arrays in programming, C# language

To make the sum of two matrices we must first make sure that both matrices have the same size, if this is correct we proceed to go through each element of the matrices and perform the sum element by element, assigning the result to a new matrix previously declared.

Fig. 2: Algoritmo para sumar dos matrices A y B implementado en lenguaje C#, ejemplo en Unity.

Analysis of the algorithm that performs the addition of two matrices

Between lines 30 and 56 we have defined a method that receives as parameters two two-dimensional arrays (“matA” and “matB”) and returns another two-dimensional array.

The result matrix is declared on line 32 and returned on line 55, at the end of the procedure.

Then in line 34 we have an IF statement to check if it is possible to solve the sum of the matrices, the condition is that the matrices match in number of rows and columns, if this is true we proceed to solve the sum, otherwise a message is printed on the console indicating that it is not possible to solve the operation and the result variable is assigned null (lines 51 and 52).

If the sum of matrices can be solved we will determine the number of rows and columns of the result matrix and we will create the data structure for that matrix, we do this in lines 36, 37 and 39 respectively.

The addition of the matrices is done element by element, therefore we will use two nested loops, the first one will go through each row and the inner loop will go through each column, so we will start with a row and go through each of the columns, at the end we will go to the next row. Inside the inner loop we simply solve the sum of the ij-elements of each matrix and assign it to the ij-element of the result matrix.

Algorithm to subtract two matrices in programming, C# language

To subtract two matrices in programming, the algorithm is practically the same as the addition, only that when their elements are traversed, instead of adding them, they are subtracted, we can see an implementation of the algorithm in Figure 3.

Fig. 3: Algorithm to subtract two matrices A and B implemented in C# language, example in Unity.

Algorithm to perform the linear combination of two matrices in programming, C# language.

Since the algorithms for adding and subtracting matrices are very similar, a function could be defined that performs a linear combination between the two matrices indicated together with their coefficients, i.e. it solves the operation:

MatrixC = a * MatrixA + b * MatrixB

In this way to perform the subtraction of matrix A minus matrix B we could call this function passing as parameter 1 for the coefficient that multiplies matrix A and -1 for the coefficient that multiplies matrix B, but we also have a function with higher capabilities. In Figure 4 we see the algorithm that solves the linear combination between both matrices.

Fig. 4: Algorithm to solve the linear combination of two matrices A and B implemented in C# language, example in Unity.

Introduction

In previous entries we saw how to define matrices in programming and load data into them, in this article we will see an algorithm to transpose a matrix in programming, using C# language in Unity.

Initial data

We will start from an “A” matrix with preloaded data and we will analyze a method that will perform the transposition of the matrix sent as parameter and will return the result matrix.

Fig. 1: Declaration of a matrix “A” and call to a function that returns its transposed matrix.

Algorithm for transposing matrix of N rows and M columns

Transpose a matrix implies transforming its rows into columns and its columns into rows, therefore the resulting matrix will be a matrix that will have its dimensions exchanged. The function that will be in charge of transposing the matrix that enters as parameter is shown in figure 2, first we will read the number of rows and columns of the input matrix and we will create the structure of the result matrix, this is done in lines 30, 31 and 32 respectively, notice how in the creation of the result matrix, the dimension is exchanged comparing with the input matrix.

Then we have to traverse each element of the input matrix, we have seen that this could be done by two nested for-loops, the first one traverses rows and the inner loop traverses columns. Inside the loop what we will do is to assign the ij-element of the input matrix, to the ji-element of the output matrix.

At the end of the loop, the result matrix is returned (line 41).

Fig. 2: Algorithm for transposing a matrix.

Introduction

In mathematics, a matrix is a structure containing numerical data arranged in rows and columns, one of its main uses is to represent and solve systems of linear equation.

In this article you will see how to represent a matrix and load data to it in C# language in Unity Engine.

About the development environment, script creation and execution

For this example we will use the Unity engine, create a C# Script and assign it to a GameObject in the scene, when pressing the Play button, Unity will automatically execute some functions inside the Script.

Implementation of a matrix in programming

Declaration of data

Matrices have a certain number of rows and columns, so we will need two integers, let’s call them “rows” and “columns”.

To declare the matrix in programming we will use a two-dimensional arrays and we must indicate the data type, usually we are going to work with the set of real numbers, so the data type we are going to use is “float”. However we could define arrays of any data type needed, for example “bool”, “int”, “double”, “string”, etc.

The declaration of the required data would be as follows:

Fig. 1: Data declaration to represent a matrix size “rows” by “columns”.

To declare a two-dimensional array, brackets are used and a comma is placed for each extra dimension that is needed, in this case as we need two dimensions it looks like this: “[ , ]”.

Initialization of the matrix data

In the previous step we declared the necessary variables, now it is time to initialize those variables, that is to say to give them concrete values or to create data structures and assign them. The initialization will be done in the “Start” method of the Script, the Start and Update functions are automatically defined when creating a new Script. By pressing the Play button in Unity, the Start functions of all the scripts present in the scene will be automatically executed, this will happen before the the first frame of the program appears on the screen.

In figure 2 we see an example of the initialization of a 2×2 matrix, in lines 17 and 18 is the initialization of the rows and columns respectively. In line 20 a two-dimensional array is created indicating the total number of elements of each dimension and this array is assigned to the “myMatrix” field that was declared in the previous step.

Fig. 2: Inicialización de los datos necesarios para representar una matriz de 2 filas y 2 columnas.

In C# the first element of the arrays is 0 and the last is “n-1”, where n is the size of the array, so in line 22 for example, the data in position [0,0] refers to the element in the first row and first column.

Conclusion

We have seen how to declare two-dimensional arrays that can be used to represent matrices and subsequently perform operations between them.

In this example the data type used for the array is “float”, which means that each element will have a number with decimal point stored, but you could define arrays of any data type you need, for example “bool”, “int”, “double”, “string”.

To read or modify an element within the matrix we use the name with which it was defined and between brackets we indicate the row and column separated by comma, so for example if we write “myMatrix[1,0]” we are pointing to the element of the matrix that is in the second row, first column.

Exit mobile version
Secured By miniOrange