Debug.Log() v.s. print()

 Debug.Log() v.s. print() 

difference bewtween Debug.Log() and print():

In fact, they are identical. print() is a simple encapsulation of Debug.Log()
According to the following screenshot. We can know Debug.Log() is in the class UnityEngine. And print() is in the class UnityEngine.Monobehaviour.

screenshot:
 



 

code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PrintScript : MonoBehaviour
{
    [Header("Counter")]
    public int Counter = 0;

    [Header("Message")]
    public string Message = "not initialized!";
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        ChangeMessage();
    }
    private void ChangeMessage()
    {
        Counter += 1;
        Message = "this is the "+Counter.ToString()+ " to call func. ChangeMessage().";
        print("print:"+Message);
        Debug.Log("Debug.Log:"+Message);
        Debug.LogWarning("Debug.LogWarning:"+Message);
        Debug.LogError("Debug.LogError:"+Message);
    }
}

source:

Comments

Popular posts from this blog

GameObject.SetActive() v.s. GameObject.active

output message to Unity Console - Debug.Log() v.s. Debug.LogWarning() v.s. Debug.LogError() v.s. print()