1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | using System.Collections; using System.Collections.Generic; using UnityEngine; public class GridGenerator : MonoBehaviour { public GameObject line; private float timeOffset; public int lineNum = 10; public float lineLength = 100.0f; public float speed = 1.0f; //public float offset = 2.0f; private LineRenderer[] lines; private LineRenderer renderLine; private Vector3 pos; void Start() { lines = new LineRenderer[lineNum]; pos = this.transform.position; horizonLines(); verticalLines(); } private void Update() { lineMoveToUP(); } //first line genarte public void instLine() { var Obj = Instantiate(line, pos, Quaternion.identity); Obj.transform.SetParent(transform); renderLine = Obj.GetComponent<LineRenderer>(); renderLine.useWorldSpace = false; } //vertical lines genarte private void verticalLines() { for (int i = 0; i < lineNum; i++) { instLine(); for (int j = 0; j < 2; j++) { renderLine.SetPosition(j, new Vector3(pos.x + (i * (lineLength / lineNum)), pos.y, pos.z + (j * lineLength))); } } } //horizontal lines genarate private void horizonLines() { for (int i = 0; i < lineNum; i++) { instLine(); for (int j = 0; j < 2; j++) { renderLine.SetPosition(j, new Vector3(pos.x + (j * lineLength), pos.y, pos.z + (i * (lineLength / lineNum)))); } lines[i] = renderLine; } } //line move to up private void lineMoveToUP() { timeOffset += Time.deltaTime * speed; for (int i = 0; i < lineNum; i++) { for (int j = 0; j < 2; j++) { lines[i].SetPosition(j, new Vector3(pos.x + (j * lineLength), pos.y, pos.z + ((i * (lineLength / lineNum) + timeOffset) % lineLength))); } } } } | cs |
'programming > c#' 카테고리의 다른 글
유니티 colorPulse (0) | 2020.02.19 |
---|---|
유니티 textureOffset (0) | 2020.02.19 |
유니티 객체 생성하기 (Instantiate) (0) | 2020.02.02 |
유니티 Physics - 움직임의 jitter를 줄이는 방법 (0) | 2020.01.04 |
GPU Instancing 최적화! 최적화! (1) | 2020.01.01 |