Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UnityGL6 : MonoBehaviour {
static Material lineMaterial;
static int objectCount=100;
static void CreateLineMaterial (){
if (!lineMaterial){
// Unity has a built-in shader that is useful for drawing
// simple colored things.
Shader shader = Shader.Find ("Hidden/Internal-Colored");
//Shader shader = Shader.Find ("Custom/Texture");
lineMaterial = new Material (shader);
lineMaterial.hideFlags = HideFlags.HideAndDontSave;
// Turn on alpha blending
lineMaterial.SetInt ("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
lineMaterial.SetInt ("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
// Turn backface culling off
lineMaterial.SetInt ("_Cull", (int)UnityEngine.Rendering.CullMode.Off);
// Turn off depth writes
lineMaterial.SetInt ("_ZWrite", 0);
}
}
public void OnRenderObject (){
CreateLineMaterial ();
// Apply the line material
lineMaterial.SetPass (0);
GL.PushMatrix ();
// Set transformation matrix for drawing to
// match our transform
GL.MultMatrix (transform.localToWorldMatrix);
// Draw lines
GL.Begin (GL.LINES);
GL.Color (new Color (0, 1, 0.25f, 0.8F));
//星を描く
for(int m=0;m<objectCount;m++){
float i= Random.Range(-20,m);
float j = Random.Range(-40,m);
GL.Vertex3 (-0.71f+i*3,1.49f+j*3,5.0f);
GL.Vertex3 (-1.72f+i*3,-1.68f+j*3,5.0f);
GL.Vertex3 (-1.72f+i*3,-1.68f+j*3,5.0f);
GL.Vertex3 (0.82f+i*3,0.15f+j*3,5.0f);
GL.Vertex3 (0.82f+i*3,0.15f+j*3,5.0f);
GL.Vertex3 (-2.3f+i*3,0.15f+j*3,5.0f);
GL.Vertex3 (-2.3f+i*3,0.15f+j*3,5.0f);
GL.Vertex3 (0.3f+i*3,-1.68f+j*3,5.0f);
GL.Vertex3 (0.3f+i*3,-1.68f+j*3,5.0f);
GL.Vertex3 (-0.71f+i*3,1.49f+j*3,5.0f);
}
GL.End ();
GL.PopMatrix ();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment