Unity 3D Training Camp

Coding with C# part-3

Coding with C# Part-3

1- Static Key Word

2- Abstract Classes

3- MonoBehavior 

Coding with C# Part-3

1- Static Key Word

How Memory Treats instances of objects ?

How to Create a shareable parameter between Fields ?

1- Static Key Word

How CPU Treats instances of objects ?

CPU (Processor) create object in a shape of Fields that contains each type of object to their class.

1- Static Key Word

How CPU Treats instances of objects ?

1- Static Key Word

How to Create a shareable parameter between Fields ?

We use Static Word

public class Student{
	string FullName;
    .
    .
    int resgestrationNumber; //Matricule
    static int CurrentRN;
    .
    .
    .
}

1- Static Key Word

How CPU Treats Static attributes ?

Coding with C# Part-3

2- Abstract Classes

What is an abstract class ?

How to create an abstract class?

What is an abstract method ?

Virtual Methods.

2- Abstract Classes

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.

2- Abstract Classes

How to create an abstract class?

Simply we add the word abstract before the class keyword.

public abstract class Animal{
	.
    .
    .
    .
}

2- Abstract Classes

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");
    }
}

Coding with C# Part-3

3- MonoBehavior

What is MonoBehavior ?

Behaviour Attributes 

MonoBehavior Methods

3- MonoBehavior

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.

3- MonoBehavior

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.

3- MonoBehavior

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

Coding with C# Part-3

Made with Slides.com