mos*_*alf 4 c# unity-game-engine
这是我的脚本,我试图制作"",以防它不是其中一个案例:
using UnityEngine;
using System.Collections;
public class DetectPlayer : MonoBehaviour {
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.name == "Platform")
{
Debug.Log("Touching Platform");
}
else
{
Debug.Log("");
}
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.name == "OnTop Detector")
{
Debug.Log("On Top of Platform");
GameObject findGo = GameObject.Find("ThirdPersonController");
GameObject findGo1 = GameObject.Find("Elevator");
findGo.transform.parent = findGo1.transform;
}
else
{
Debug.Log("");
}
}
}
Run Code Online (Sandbox Code Playgroud)
但这""不起作用.在游戏运行时,它不会从控制台中删除文本.而且当我停止游戏并再次运行它时,它会继续显示Debug.Log的最后一个文本.
如果在我的脚本中没有发生If,我想清除它.
我看到了这个答案:
但我不确定这是否是我需要的以及如何使用它.制作一个新剧本?
还有错误呢.如果我清除登录控制台,它会删除erorrs,如果有一些?
在这个屏幕截图中,我触摸平台然后离开它后处于状态,但文本仍然存在于控制台日志中:
该Debug.ClearDeveloperConsole()功能用于当从而建的应用程序,您清除日志调试构建在您的项目启用.有没有清除编辑日志官方的API.
大多数编辑器功能都可以Reflection像隐藏Gizmos和切换统计面板一样进行复制.我打算写一个,但发现了这一个.
这应该清除Console选项卡上的每个日志.
using System.Reflection;
public void ClearLog()
{
var assembly = Assembly.GetAssembly(typeof(UnityEditor.ActiveEditorTracker));
var type = assembly.GetType("UnityEditorInternal.LogEntries");
var method = type.GetMethod("Clear");
method.Invoke(new object(), null);
}
Run Code Online (Sandbox Code Playgroud)
现在,您可以ClearLog();在其他语句中调用.
编辑:
最近在~Union 2017中已经发生了变化.由于它是通过反射完成的,我认为如果Unity重命名此代码中使用的任何类,变量或函数,它将随时再次更改.以下是执行此操作的新方法:
public void ClearLog()
{
var assembly = Assembly.GetAssembly(typeof(UnityEditor.Editor));
var type = assembly.GetType("UnityEditor.LogEntries");
var method = type.GetMethod("Clear");
method.Invoke(new object(), null);
}
Run Code Online (Sandbox Code Playgroud)