Created
August 26, 2021 05:50
-
-
Save kitasenjudesign/865f09470b156b04f6fdc1974d4597e3 to your computer and use it in GitHub Desktop.
simple lines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Lines : MonoBehaviour | |
{ | |
[SerializeField] private MeshFilter _meshFilter; | |
private Vector3[] _positions; | |
private Mesh _mesh; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
_mesh = new Mesh(); | |
_positions = new Vector3[100]; | |
int[] indices = new int[100]; | |
for(int i=0;i<100;i++){ | |
_positions[i] = new Vector3( | |
10f * (Random.value-0.5f), | |
10f * (Random.value-0.5f), | |
10f * (Random.value-0.5f) | |
); | |
indices[i] = i; | |
} | |
_mesh.vertices = _positions; | |
_meshFilter.mesh = _mesh; | |
_mesh.SetIndices(indices, MeshTopology.Lines, 0); | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
for(int i=0;i<_positions.Length;i++){ | |
if(i%2==0){ | |
_positions[i]=Vector3.zero; | |
}else{ | |
_positions[i] = new Vector3( | |
10f * (Random.value-0.5f), | |
10f * (Random.value-0.5f), | |
10f * (Random.value-0.5f) | |
); | |
} | |
} | |
_mesh.vertices = _positions; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment