Unity Debug.Log() vs print() | C# Object type | Boxing & Unboxing in C# - Unity C# Scripting 03
Notes for You::
0:00:55 Understand Unity print( ) function: • Unity Debug.Log() vs print() | C# Obj...
Example Code:
using UnityEngine;
public class FirstScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
print("Hello Unity");
}
}
print() :
- Logs message to the Unity Console (identical to Debug.Log() method).
Syntax of print()function: In MonoBehaviour class
public static void print(object message) // method header
{
Debug.Log(message); // method body
}
where:
print- is a function name
void- is the return type
static- indicates it is an classmember
public - indicates it can be accessed globally
message - is a parameter of type object
0:04:00 Understand Object type in C#: • Unity Debug.Log() vs print() | C# Obj...
object:
- is a reference type can hold any type of data, by default null.
message:
- is a memory location, a box to hold a value
using UnityEngine;
public class FirstScript : MonoBehaviour
{
void Start()
{
object wish = "Hello Unity"; // can hold string
print(wish);
object num = 22; // can hold integer
print(num);
}
}
0:12:06 Understand Boxing and Unboxing in C#: • Unity Debug.Log() vs print() | C# Obj...
Boxing :
- wrapping a primitive data into an object
Un-Boxing :
- unwrapping primitive data from an object
using UnityEngine;
public class FirstScript : MonoBehaviour
{
void Start()
{
// boxing : storing primitive data into an object
object message = 22; // object can hold anything
// unboxing : getting primitive data out of an object
// int num = message; // error: Cannot implicitly convert type object to int
int num = (int)message; // using typecasting
print(num);
}
}
0:22:30 Understand Unity Debug.Log( ) method: • Unity Debug.Log() vs print() | C# Obj...
Example Code:
using UnityEngine;
public class FirstScript : MonoBehaviour
{
void Start()
{
Debug.Log("Hello Unity");
}
}
Debug.Log() :
- Logs message to the Unity Console.
Log() method syntax: In Debug class
public static void Log(object message)
{
Debug.Interna_Log(0,(message==null) ? "Null" :message.ToString(),null);
}
where
Debug.Interna_Log
- is actually responsible for displaying message to the Console panel.
- if message is equal to null then displays Null on the Console else converts the message to string and displays it.
Note: It is recommended to use Debug.Log() method instead of using print() function.
=========================================
Follow the Link For Next Video:
• Unity Assembly Browser | Assembly Ref...
Follow the Link For Previous Video:
• Unity Editor Layout | First C# Script...
=========================================
Unity C# Scripting Tutorials Playlist:-
• Unity C# Scripting Tutorials
=========================================
Watch My Other Useful Tutorials:-
Unity Scripting API - Introduction Tutorials:-
• Unity Scripting API - Intro Tutorials
Unity Scripting API - MonoBehaviour Tutorials:-
• Unity Scripting API - MonoBehaviour T...
Unity Scripting API - Time Tutorials:-
• Unity Scripting API - Time Tutorials
Unity Scripting API - Transform Tutorials:-
• Unity Scripting API - Transform Tutor...
Unity Scripting API - Input Tutorials:-
• Unity Scripting API - Input Tutorials
Unity Google VR Tutorials:-
• Unity Google VR Tutorials
=========================================
Subscribe to our YouTube channel:-
/ chidrestechtutorials
Join as Member of our YouTube channel:-
https://www.youtube.com/chidrestechtu...
Become our Patron:-
/ chidrestechtutorials
Visit our Website:-
https://www.chidrestechtutorials.com
Download our Notes from Instamojo:-
https://chidrestechtutorials.myinstam...
Buy our Products on Spring:-
https://chidres-tech-tutorials.creato...
=========================================
Follow Us:-
Google My Business:-
https://chidrestechtutorials.business...
Google Blog:-
http://manjunathchidre.blogspot.com
LinkedIn:-
/ chidrestechtutorials
Facebook:-
/ chidrestechtutorials
Twitter:-
/ manjunathchidre
Tumblr:-
/ chidrestechtutorials
Pinterest:-
/ chidrestechtutorials
=========================================
Despite my inconsistent uploads; Thanks for being amazing learners and still sticking with me on YouTube.
=========================================
Hash Tags:-
#ChidresTechTutorials #UnityCSharpScripting #UnityCSharpScriptingTutorial #UnityScripting #Unity