Teaching Newbies since 2014

kauress

  • Home
  • Javascript ❤
    • JavaScript
    • Node.js
  • WebDev Tuts
  • screencasts
  • Resources
  • VR & AR
  • Contact
  • Github
  • Twitter
  • YouTube
  • RSS
  • C++
You are here: Home / Unity3D / Unity3D Scripting API -2: MonoBehaviour

January 22, 2021 by: Kauress

Unity3D Scripting API -2: MonoBehaviour

💚MonoBehaviour💚 is the base class from which every Unity script derives. Any Unity3D script that you create will extend the MonoBehaviour class.

Ok what is a class? When you make a new Unity3D script, the class name will be the same as the file name. A class is like a container for your variables and functions. They’re organized together and perform a specific function in your game, for example character movement script will be a class by itself.

The MonoBehaviour class will execute events in a per-determined/certain order

For example:

⭐ Start(): This method is called right at the start of the game before Update() is called
⭐ Update(): Update method is called every frame
⭐ Awake(): Awake method is called when the script instance is being loaded
⭐ onDestroy(): Called when an object is destroyed⭐ OnCollisionEnter(): When 2 colliders hit/touch each other

Full list here: https://docs.unity3d.com/ScriptReference/MonoBehaviour.html

To use any of these event methods, your script must extend from the MonoBehaviour class which contains all these events methods.

🍱Method: A method is a function that performs a specific task. So these methods are performing a specific function. For example whatever code is written inside the Start() will execute when the game starts.

Introduction to the Unity3D Scripting API – 1
Unity3D Scripting API #3 – Start() 🏁

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2021 ·Kauress