Saltar al contenido

ejemplo de código de herencia de unity c# monobehaviour

Puede que se de el caso de que encuentres algún error con tu código o trabajo, recuerda probar siempre en un ambiente de testing antes subir el código al proyecto final.

Ejemplo: unidad por qué heredar monbehaviour

Yes, your classes don't have to inherit from MonoBehaviour,and you can instantiate them in the normal way (using 'new').

Inheriting from MonoBehaviour simply gives your scripts extra abilities, 
such asbeingable to:- be placed on gameobjects
- have public vars which can be adjusted in the inspector
- receive Unity events such asStart()Update()FixedUpdate() etc.

It's worth noting that while you can instantiate other classes using 'new',
you shouldn't use 'new' to create new instances of your MonoBehaviour scripts.

This isbecause there are many areas wherethe functionality of the Monobehaviour relies on
assuming that it's attached to a GameObject,andif you create a new one without it being attached to a GO, 
it can cause it to malfunction and give errors.

For this reason, to create a new instance of a MonoBehaviour at runtime,
you should always use AddComponent to create and attach it to an existing gameobject at runtime.

Tienes la opción de añadir valor a nuestro contenido aportando tu veteranía en las observaciones.

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *