public void RandomDivision() { LeModule module = childModule; if (ExtRandom <bool> .Chance(1, 10)) { LeModule.axis newAxis = RandomAxis(); module.Subdivide(newAxis); foreach (var child in module.children) { Renderer renderer = child.go.GetComponent <Renderer>(); RandomColor(renderer); child.gameObject.AddComponent <ModuleSwitcher>(); child.gameObject.AddComponent <ModuleCollider>(); child.gameObject.AddComponent <ModuleMove>(); } } else { module.UnDivide(); Debug.Log("module.UnDivide()"); } }
public void RandomColorFromList(Renderer renderer, List <Color> colours) { MaterialPropertyBlock props = new MaterialPropertyBlock(); LeModule module = childModule; int index = Random.Range(0, colours.Count); Color color = colours[index]; props.SetColor("_Color", color); renderer.SetPropertyBlock(props); }
// Start is called before the first frame update void Start() { childModule = gameObject.GetComponent <LeModule>(); GameObject go = new GameObject(); go.transform.SetParent(transform); var pos = Vector3.zero; pos.y = -childModule.size.y / 2; go.transform.localPosition = pos; var a = childModule.size.y * 10; var b = a / childModule.size.x; }
// Start is called before the first frame update void Start() { module = gameObject.GetComponent <LeModule>(); lengths = new float[] { module.size.x / 2, module.size.x / 2, module.size.y / 2, module.size.y / 2, module.size.z / 2, module.size.z / 2 }; active = module.GetComponent <ModuleMove>().active; }
// Use this for initialization void Start() { module = GetComponent <LeModule>(); if (module.go) { var filter = module.go.GetComponent <MeshFilter>(); if (filter) { var bounds = filter.sharedMesh.bounds; var center = bounds.center; var size = module.size; } } }
public void RandomColor(Renderer renderer) { // Change colour randomly MaterialPropertyBlock props = new MaterialPropertyBlock(); LeModule module = childModule; if (module.go) { float r = Random.Range(0.0f, 1.0f); float g = Random.Range(0.0f, 1.0f); float b = Random.Range(0.0f, 1.0f); props.SetColor("_Color", new Color(r, g, b)); renderer.SetPropertyBlock(props); } }
public void SetTextureScale(Renderer renderer) { MaterialPropertyBlock props = new MaterialPropertyBlock(); LeModule module = childModule; if (module.go) { if (module.size.x > module.size.z) { props.SetVector("_ST", new Vector4(module.size.x * scaleFactor, module.size.y * scaleFactor, 1, 1)); } else { props.SetVector("_ST", new Vector4(module.size.z * scaleFactor, module.size.y * scaleFactor, 1, 1)); } renderer.SetPropertyBlock(props); } }
// Start is called before the first frame update void Start() { childModule = gameObject.GetComponent <LeModule>(); collider = gameObject.AddComponent <BoxCollider>(); collider.size = childModule.size; }