Skip to content

Instantly share code, notes, and snippets.

@kitasenjudesign
Created August 26, 2021 05:50
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 kitasenjudesign/865f09470b156b04f6fdc1974d4597e3 to your computer and use it in GitHub Desktop.
Save kitasenjudesign/865f09470b156b04f6fdc1974d4597e3 to your computer and use it in GitHub Desktop.
simple lines
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