unity console clear code example

Example: how to clear console through script unity

using System.Reflection; //make sure you add this!
using UnityEngine;


void Update()
{
  	if (Input.GetKey("space"))
    {
      	ClearLog() //when you call this function it will clear the console
    }
}


public void ClearLog() //you can copy/paste this code to the bottom of your script
{
    var assembly = Assembly.GetAssembly(typeof(UnityEditor.Editor));
    var type = assembly.GetType("UnityEditor.LogEntries");
    var method = type.GetMethod("Clear");
    method.Invoke(new object(), null);
}