unity如何在摄像机上绘制矩形,请给出可直接运行的程序
时间: 2023-06-26 20:04:05 浏览: 160
以下是一个简单的Unity程序,可以在摄像机上绘制矩形:
```
using UnityEngine;
public class DrawRect : MonoBehaviour
{
public Material mat; // 用于绘制矩形的材质
void OnPostRender()
{
GL.PushMatrix();
mat.SetPass(0);
GL.LoadOrtho();
GL.Begin(GL.QUADS);
GL.Color(Color.red); // 设置矩形颜色
GL.Vertex3(0.25f, 0.25f, 0);
GL.Vertex3(0.75f, 0.25f, 0);
GL.Vertex3(0.75f, 0.75f, 0);
GL.Vertex3(0.25f, 0.75f, 0);
GL.End();
GL.PopMatrix();
}
}
```
将此脚本添加到摄像机上,并将`mat`属性设置为一个包含红色颜色的材质即可。在场景中运行后,会在摄像机视角中绘制一个红色矩形。
阅读全文
相关推荐













