编程时调试是不可缺少的,Unity中用于调试的方法均在Debug类中。
浅试一下
新建一个物体和脚本,并把脚本挂载到物体上!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DeBugTest : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("test");
    }
    // Update is called once per frame
    void Update()
    {
        
    }
}
 
运行一下:
 
总结

Debug.Log("test");
Debug.LogWarning("test1");
Debug.LogError("test3"); 
 
//绘制一条射线   参数:起点,终点
Debug.DrawLine(Vector3.zero, Vector3.one); 

//绘制一条线,并更改他的颜色
Debug.DrawLine(Vector3.zero, Vector3.one,Color.gray); 
//绘制一条射线   参数:起点,射线
Debug.DrawRay(Vector3.zero, Vector3.up, Color.yellow); 

射线是给他一个起点和方向!
由于是调试方法,因此直线不会显示在游戏中!
那直线和射线的区别呢?
    void Update()
    {
        //绘制一条射线   参数:起点,射线
        Debug.DrawLine(new Vector3(1, 0, 0), new Vector3(1, 1, 0), Color.blue);
        Debug.DrawRay(new Vector3(1, 0, 0), new Vector3(1, 1, 0), Color.red);
    }
} 
因为要持续进行绘制,所以把绘制代码放在Update方法中。
 
验证:
void Update()
{
    //绘制一条射线   参数:起点,射线
    Debug.DrawLine(new Vector3(1, 0, 0), new Vector3(1, 1, 0), Color.blue);
    Debug.DrawRay(new Vector3(1, 0, 0), new Vector3(2, 1, 0), Color.red);
} 




















