Unity使用GL画线
脚本需挂在相机上,如果你的脚本,编辑器报错了,Matrix stack full depth reached,加上这个方法试试GL.LoadPixelMatrix();
using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class GridLine : MonoBehaviour { public static bool isShowGridLine=false;
Material lineMaterial;
private void Awake()
{
if (!lineMaterial)
{
lineMaterial = new Material(Shader.Find("Particles/Alpha Blended"));
lineMaterial.hideFlags = HideFlags.HideAndDontSave;
lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
}
}
void OnPostRender()
{
if (isShowGridLine) {
GL.PushMatrix();
lineMaterial.SetPass ();
//如果报错的话,将这句话取消注释后,再试试
// GL.LoadPixelMatrix ();
GL.LoadOrtho ();
GL.Begin (GL.LINES);
for (int i = ; i < ; i++) {
GL.Color (Color.green);
//横线
GL.Vertex3 (,i/10f,);
GL.Vertex3 (,i/10f,);
//竖线
GL.Vertex3 (i/10f,,);
GL.Vertex3 (i/10f,,);
}
// //斜线
// GL.Vertex3(0,0,0);
// GL.Vertex3 (1,1,0); GL.End ();
GL.PopMatrix ();
} }
void Update()
{
if (Input.GetMouseButtonDown()) {
isShowGridLine = true;
}
if (Input.GetKeyDown(KeyCode.Escape)) {
isShowGridLine = false;
} }
}

Unity使用GL画线的更多相关文章
- Unity之屏幕画线
using UnityEngine;using System.Collections; public class DrawRectangle : MonoBehaviour { public Colo ...
- unity gl 画线
using UnityEngine; using System.Collections; public class TGLLine : MonoBehaviour { private static M ...
- unity3d 使用GL 方式画线
这个是画线部分 private Vector3[] linePoints; public int m_LineCount; public int m_PointUsed; public void Re ...
- Unity GL画折线
新建一个脚本,这个物体得挂在有摄像机组件的物体上才能生效 OnPostRender() 这个函数才会被自动调用(类似生命周期自动调用) 然后就可以代码画线了,原理是openGL的画线 using Un ...
- Unity GL 画圆
Unity下GL没有画圆的函数,只能自己来了. 如果能帮到大家,我也很高兴. 虽然没有画圆的函数,但是能画直线,利用这一点,配合微积分什么的,就可以画出来了.反正就是花很多连在一起的直线,每条直线足够 ...
- 用GL画出人物的移动路径
注意:用Debug画的线会存在穿透问题 没啥好解释的,直接看代码: using UnityEngine; using System.Collections; using System.Collecti ...
- unity3d之在屏幕上画线
如何在屏幕上画线,简单的代码如下: using UnityEngine; public class Test : MonoBehaviour { void OnGUI() { GL.LoadOrtho ...
- WebGl 画线
效果: 代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- OpenGL进阶演示样例1——动态画线(虚线、实线、颜色、速度等)
用OpenGL动态绘制线段.事实上非常easy,但到如今为止.网上可參考资料并不多. 于是亲自己主动手写一个函数,方便动态绘制线段.代码例如以下: #include<GL/glu ...
随机推荐
- HTML&CSS Table元素详细解说
1.预热 css样式多如牛毛,我不可能一个一个去讲,那样好像背字典一样,我相信你们也不喜欢这样的方式.所以,我会在实战中慢慢和你讲解,然后,你记住一些重要的css属性就可以了.关键是,你要学会去查资料 ...
- Xamarin自定义布局系列——瀑布流布局
Xamarin.Forms以Xamarin.Android和Xamarin.iOS等为基础,自己实现了一整套比较完整的UI框架,包含了绝大多数常用的控件,如下图 虽然XF(Xamarin.Forms简 ...
- Archlinux 的U盘自动装载(三)udevil
U盘的自动装载方法,目前我已经使用过以下几种方法: udev 规则 基于 udev 规则的 Shell script udisks 以及 udisks2 结果,总是存在这样那样的小问题.例如,文件名乱 ...
- netflix zuul 学习
netflix zuul 是netflix开发的一个EDGE SERVICE. 主要是作为一个API Gateway 服务器,可以实现安全,流量控制等功能. 我看的是1.x的版本,Zuul1.x的实现 ...
- C语言之一天一个小程序
程序示例: #include <stdio.h> #include <stdlib.h> int main() { printf("Hello,world!\n&qu ...
- linux上执行 xhost unable to open display
linux下执行xhost命令报错:unable to open display,解决方法,linux 下通过xhost进入图形界面,经常会出现报错"unable to open disp ...
- X64系统下IIS运行ASP网站HTTP500错误 【安装FoxMail Server时出现】
错误如上 解决办法 使用管理员模式运行CMD 输入cscript C:\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitA ...
- IOS推送--之开发模式测试
参考文章:http://blog.csdn.net/showhilllee/article/details/8631734#comments 第一步.下载你工程的开发证书 第二步.从钥匙串访问中导出秘 ...
- Docker remote API简单配置使用
1.启动docker remote API的方式如下: docker -d -H uninx:///var/run/docker.sock -H tcp://0.0.0.0:5678 2.但是为了伴随 ...
- Tcl与Design Compiler (四)——DC启动环境的设置
本文属于原创手打(有参考文献),如果有错,欢迎留言更正:此外,转载请标明出处 http://www.cnblogs.com/IClearner/ ,作者:IC_learner 主要内容有: ·启动环 ...