Skip to content

Instantly share code, notes, and snippets.

@kjellski
Created November 3, 2013 18:55
Show Gist options
  • Save kjellski/7293517 to your computer and use it in GitHub Desktop.
Save kjellski/7293517 to your computer and use it in GitHub Desktop.
Creeping With Unity
using System;
using UnityEngine;
[ExecuteInEditMode]
[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
[RequireComponent(typeof(MeshCollider))]
public class CreepCell : MonoBehaviour, IFillable
private readonly Vector3[] _vertices = new Vector3[_verticesCount];
private readonly Vector3[] _normals = new Vector3[_verticesCount];
private readonly Vector2[] _uv = new Vector2[_verticesCount];
private readonly int[] _triangles = new int[_trianglesCount];
public float FillingHeight;
...
//init mesh
// recalculate mesh on FillingLevel...
}
using UnityEngine;
public class CreepSpreader : MonoBehaviour
{
private const int _widht = 3;
private const int _height = 3;
public CreepCell[,] creep = new CreepCell[_widht, _height];
public CreepSpread<CreepCell> spread;
// Use this for initialization
void Start()
{
for (int z = 0; z < _height; z++)
{
for (int x = 0; x < _widht; x++)
{
Vector3 pos = new Vector3(x,0,z);
// this obviously doesn't work in runtime, since this loads the prefab...
// how could I get an instance of my CreepCell to be loaded when I'm unable to
// instantiate it? or how would I do get a hold of all the instances in the array?
creep[x, z] = (CreepCell) Instantiate(Resources.Load("CreepCell"), pos, Quaternion.identity);
}
}
spread = new CreepSpread<CreepCell>(_height,_widht, creep);
}
// Update is called once per frame
void Update()
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment