Monobehaviour unity что это

от admin

MonoBehaviour

MonoBehaviour is the base class from which every Unity script derives.

When you use C#, you must explicitly derive from MonoBehaviour.

This class doesn’t support the null-conditional operator (?.) and the null-coalescing operator (??).

For code samples, see the individual MonoBehaviour methods.

Note: There is a checkbox for enabling or disabling MonoBehaviour in the Unity Editor. It disables functions when unticked. If none of these functions are present in the script, the Unity Editor does not display the checkbox. The functions are:

MonoBehaviour

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Description

MonoBehaviour is the base class from which every Unity script derives.

When you use C#, you must explicitly derive from MonoBehaviour.

This class doesn’t support the null-conditional operator (?.) and the null-coalescing operator (??).

For code samples, see the individual MonoBehaviour methods.

Note: There is a checkbox for enabling or disabling MonoBehaviour in the Unity Editor. It disables functions when unticked. If none of these functions are present in the script, the Unity Editor does not display the checkbox. The functions are:

MonoBehaviour

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Description

MonoBehaviour is a base class that many Unity scripts derive from.

MonoBehaviour offers life cycle functions that make it easier to develop with Unity.

MonoBehaviours always exist as a Component of a GameObject, and can be instantiated with GameObject.AddComponent. Objects that need to exist independently of a GameObject should derive from ScriptableObject instead.

A MonoBehaviour can be deleted with Object.Destroy or Object.DestroyImmediate. When the parent GameObject is destroyed all components are automatically deleted, including MonoBehaviours.

After the underlying component is destroyed, the C# object for the MonoBehaviour remains in memory until garbage is collected. A MonoBehaviour in this state acts as if it is null. For example, it returns true for a «obj == null» check. However, this class doesn’t support the null-conditional operator (?.) and the null-coalescing operator (??).

Читать:
Как поменять имя в канале дискорда

When a MonoBehaviour is serialized, the value of C# fields are included according to Unity’s Serialization rules. See Script Serialization for details. The serialized data also includes internal properties, such as the reference to the MonoScript that tracks the implementation class for the object.

For code samples, see the individual MonoBehaviour methods.

Note: There is a checkbox for enabling or disabling MonoBehaviour in the Unity Editor. It disables functions when unticked. If none of these functions are present in the script, the Unity Editor does not display the checkbox. The functions are:

Важные классы — MonoBehaviour

Класс MonoBehaviour — это базовый класс, от которого по умолчанию наследуется каждый скрипт Unity. Когда вы создаете сценарий C# из окна проекта Unity окна, в котором отображается содержимое ваших активов Папка (вкладка «Проект») Подробнее
См. в Словарь , он автоматически наследуется от MonoBehaviour и предоставляет вам шаблон сценарий. Дополнительную информацию об этом см. в разделе Создание и использование сценариев.

Класс MonoBehaviour предоставляет структуру, позволяющую прикрепить сценарий к GameObject фундаментальному объекту в сценах Unity, который может представлять персонажей, реквизит, декорации, камеры, путевые точки и многое другое. Функциональность GameObject определяется прикрепленными к нему компонентами. Подробнее
См. Словарь в редакторе, а также ссылки на полезные события, такие как как Запуск и Обновление.

Полный справочник по каждому члену класса MonoBehaviour и его технические подробности см. в справочнике по скрипту MonoBehaviour.

Сопрограммы

Класс MonoBehaviour позволяет запускать, останавливать и управлять сопрограммами, которые представляют собой способ написания асинхронного кода, который может включать ожидание в течение определенного времени или выполнения определенных действий, позволяя при этом другому коду продолжать выполнение. .

События

Класс MonoBehaviour предоставляет доступ к большому набору сообщений о событиях, что позволяет вам выполнять код на основе того, что в данный момент происходит в вашем проекте. Вот несколько наиболее распространенных примеров. Полный список см. в разделе Сообщения на странице справки по сценариям MonoBehaviour

Start — вызывается, когда GameObject начинает существовать (либо при загрузке сцены, или создается экземпляр GameObject).

Update — вызывается каждый кадр.

FixedUpdate – вызывается каждый временной шаг физики.

OnBecameVisible и OnBecameInvisible — вызывается, когда средство визуализации GameObject входит или выходит из камеры Компонент, который создает изображение определенной точки обзора в вашей сцене. Вывод либо рисуется на экране, либо фиксируется в виде текстуры. Подробнее
Посмотреть в представлении Словарь .

OnCollisionEnter и OnTriggerEnter — вызывается при столкновениях физики Столкновение происходит, когда физический движок обнаруживает, что коллайдеры двух игровых объектов соприкасаются или перекрываются, когда хотя бы один из них имеет компонент Rigidbody и находится в движении. Подробнее
См. в Словарь или возникают триггеры.

Похожие статьи