Youcef Madadi
Web and game development teacher
Coding with C# part-3
1- Static Key Word
2- Abstract Classes
3- MonoBehavior
How Memory Treats instances of objects ?
How to Create a shareable parameter between Fields ?
How CPU Treats instances of objects ?
CPU (Processor) create object in a shape of Fields that contains each type of object to their class.
How CPU Treats instances of objects ?
How to Create a shareable parameter between Fields ?
We use Static Word
public class Student{
string FullName;
.
.
int resgestrationNumber; //Matricule
static int CurrentRN;
.
.
.
}
How CPU Treats Static attributes ?
What is an abstract class ?
How to create an abstract class?
What is an abstract method ?
Virtual Methods.
What is an abstract class ?
An abstract type is a type in a nominative type system that cannot be instantiated directly.
Example:
You can't Create an instance of an Animal without specifying its type.
How to create an abstract class?
Simply we add the word abstract before the class keyword.
public abstract class Animal{
.
.
.
.
}
What is an abstract method ?
A method which is declared abstract, has no “body” and declared inside the abstract class only.
And it remind us to redefine it in the subclass.
Abstract methods shouldn't be private.
public abstract class Animal{
.
.
abstract void attack();
}
public class dog : Animal{
.
.
override void attack(){
Debug.Log("bite");
}
}
What is MonoBehavior ?
Behaviour Attributes
MonoBehavior Methods
What is MonoBehavior ?
MonoBehaviour is the base class from which every Unity script derives.
When you use C# in Unity , you must explicitly derive from MonoBehaviour so you can use it as component for your Game object.
MonoBehavior derives from Behaviour class.
Behaviour Attributes
MonoBehavior is extended from Behaviour so MonoBehavior has all attributes in Behaviour .
gameObject | The game object this component is attached to. A component is always attached to a game object. |
tag | The tag of this game object. |
transform | The Transform attached to this GameObject. |
hideFlags | Should the object be hidden, saved with the Scene or modifiable by the user? |
name | The name of the object. |
MonoBehavior Methods
You can Find all the methods in the document of Unity :
https://docs.unity3d.com/ScriptReference/MonoBehaviour.html
For the flowchart of MonoBehavior :
https://docs.unity3d.com/Manual/ExecutionOrder.html
Or for the Image :
https://docs.unity3d.com/uploads/Main/monobehaviour_flowchart.svg
By Youcef Madadi