Understanding Component properties in Unity's Inspector

GameObjects have some Components that make them behave in a certain way. For instance, select Main Camera and look at the Inspector panel. One of the Components is the Camera. Without that Component, it will cease being a camera. It would still be a GameObject in your scene, just no longer a functioning camera.

Variables become Component properties

Any Component of any GameObject is just a script that defines a class, whether you wrote the script or the Unity's programmer did. We just aren't supposed to edit the scripts that Unity wrote. This means that all the properties we see in Inspector are just variables of some type. They simply store data that will be used by some methods.

Unity changes script and variable names slightly

When we add our script to a GameObject, the name of our script shows up in the Inspector panel as a Component. Unity makes a couple of small changes. You might have noticed that when we added LearningScript to Main Camera, Unity actually showed it in the Inspector panel as Learning Script. Unity added a space to separate the words of the name. Unity does this modification to the variable names, too. Notice that the variable number1 is shown as Number 1, and number2 as Number 2. Unity capitalizes the first letter as well. These displayed changes improve readability in Inspector.

Changing a property's value in the Inspector panel

There are two situations when you can modify a property value:

  • During the Play mode
  • During the development mode (not in the Play mode)

When you are in the Play mode, you will see that your changes take effect immediately in real time. This is great when you're experimenting and want to see the results.

Note

When you are in the Play mode, you will see that your changes take effect immediately in real time. This is great when you're experimenting and want to see the results. Write down any changes you want to keep because when you stop the Play mode, any changes you made will be lost.

When you are in the development mode, changes you make to the property values will be saved by Unity. This means that if you quit Unity and restart it again, the changes will be retained. Of course you won't see the effect of your change until you click on Play.

Note

The changes you make to the property values in the Inspector panel do not modify your script. The only way your script can be changed is for you to edit it in the script editor (MonoDevelop). The values shown in the Inspector panel override any values you had assigned in your script.

If you desire to undo the changes you've made in the Inspector panel, you can reset the values to the default values assigned in your script. Click on the Cog icon (the gear) on the far right of the Component script, and then select Reset as shown in the following screenshot:

Changing a property's value in the Inspector panel
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.151.164