Skip to content

Instantly share code, notes, and snippets.

@flushpot1125
Created July 1, 2017 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flushpot1125/e2e8f3c61f1d6f3f28226e5453066f6b to your computer and use it in GitHub Desktop.
Save flushpot1125/e2e8f3c61f1d6f3f28226e5453066f6b to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UnityLineRenderer4 : MonoBehaviour {
private LineRenderer lr;
private Renderer rn;
int pointCount =60000;//星は6つの点で構成されるため、星の数(objectCount)の6倍の値を入れる
static int objectCount=10000;
float[] val1= new float[objectCount];
float[] val2= new float[objectCount];
void Start () {
//多数の星をランダムに表示するためのオフセットを算出して格納
for(int i=0;i<objectCount;i++){
val1[i]= Random.Range(-100,objectCount);
val2[i] = Random.Range(-200,objectCount);
}
lr = GetComponent<LineRenderer>();
lr.SetVertexCount(pointCount);
//星を描く
for(int m=0;m<objectCount;m++){
lr.SetPosition(0+m*6,new Vector3(-0.71f+val1[m],1.49f+val2[m],5.0f));
lr.SetPosition(1+m*6,new Vector3(-1.72f+val1[m],-1.68f+val2[m],5.0f));
lr.SetPosition(2+m*6,new Vector3(0.82f+val1[m],0.15f+val2[m],5.0f));
lr.SetPosition(3+m*6,new Vector3(-2.3f+val1[m],0.15f+val2[m],5.0f));
lr.SetPosition(4+m*6,new Vector3(0.3f+val1[m],-1.68f+val2[m],5.0f));
lr.SetPosition(5+m*6,new Vector3(2.0f+val1[m],5.0f+val2[m],5.0f));
//lr.SetPosition(5+m*6,new Vector3(-0.71f+val1[m],1.49f+val2[m],5.0f));//ほんとうは最後にこれを入れると星型になる。しかしLineRendererは一筆書きしかできないので、評価のためにこれを使わなかった。
}
rn = GetComponent<Renderer>();
rn.material.SetColor("_Color",new Color(0, 1, 0.25f, 0.8F));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment