top of page
  • 作家相片Lingheng Tao

Unity Inspector #1 Basic Operations


This series of notes write about some editing skills for creating a more readable, organized script in Unity.


In MonoBehavior scripts


We know that in MonoBehavior scripts one can create many types of public variables and most of them can be set in the Unity Inspector. We can easily do this by declaring them as public variables.


For example,

public int age;

However, these variables are public, meaning that other script can also access these variables if there's an instance. We may not want this happen, but we also want the convenience to edit them in the inspector. Thus, we can create them as private variables, but have a serialized field attribute, by adding a [SerializeField] as a prefix.

[SerializeField] private int age;

Thus, we can still set this variable through the inspector, but this time age becomes a private variable, which means other scripts are not able to access it.


Usually, the attributes wrapped by square brackets are the attributes that helps to regulate the appearance of the script in the inspector. The following attributes are very useful and also frequently used, and I will add comments for what they are doing.


Variables


We will go over the following attributes.

[Header("This is the title.")]
[Tooltip("This is a description of the field.")]
[Range(1,10)]
[TextArea(1,10)]
[Multiline]





9 次查看0 則留言

最新文章

查看全部

Unity Engine #5 Physics

#GameEngine #UnityEngine #GameProgramming 这篇笔记主要写一下关于碰撞检测和刚体(Rigidbody)组件的一些特性。

Comments


bottom of page