// Use this for initialization void Start() { // find all meshfilter component Transform[] AllChildren = GetComponentsInChildren <Transform>(); foreach (Transform Child in AllChildren) { if (Child.gameObject.GetComponent <MeshFilter>() != null) { boxMorphGO = Child.gameObject.AddComponent <BoxMorphGO>(); boxMorphGO.boxMorphKeyPts = boxMorphKeyPts; } } }
void Update() { // compare current frame list values of type and rot with latest UDP json feed for (int i = 0; i < 18; i++) { int type = scanningSliderDataParser.grid.buildings[i].type; int rot = scanningSliderDataParser.grid.buildings[i].rot; if (currentTypeList[i] == type && currentRotList[i] == rot) { changedList[i] = false; //Debug.Log("unchanged"); } else { changedList[i] = true; //Debug.Log("changed"); currentTypeList[i] = type; currentRotList[i] = rot; // remove current building GO and instantiate latest one Destroy(bldgGOsGood[i]); Destroy(bldgGOsBad[i]); // instantiate buildings if (type != -1 && buildingPrefabsGood[type] != null) { //Debug.Log(string.Format("instantiating building {0} in the grid with type {1}, rot {2}", i, type, 0)); bldgGOsGood[i] = Instantiate(buildingPrefabsGood[type], buildingPositions[i].transform.position, Quaternion.Euler(0.0f, -(float)rot * 90.0f + 180.0f, 0.0f), bldgParent.transform); BoxMorphGO c1 = bldgGOsGood[i].AddComponent <BoxMorphGO>(); c1.boxMorphKeyPts = boxMorphKeyPts; bldgGOsBad[i] = Instantiate(buildingPrefabsBad[type], buildingPositions[i].transform.position, Quaternion.Euler(0.0f, -(float)rot * 90.0f + 180.0f, 0.0f), bldgParent.transform); BoxMorphGO c2 = bldgGOsBad[i].AddComponent <BoxMorphGO>(); c2.boxMorphKeyPts = boxMorphKeyPts; } // instantiate wave effect for only type 20 and 21 (pyramid and empirestate) if (type == 20 || type == 21) { //Debug.Log(string.Format("instantiating wave effect in the grid with type {1}, rot {2}", i, type, 0)); Instantiate(waveEffect, buildingPositions[i].transform.position + new Vector3(0.0f, waveEffectPosY, 0.0f), Quaternion.Euler(0.0f, 0.0f, 0.0f), bldgParent.transform); } } } }