private void PlayGridEnter() { List <GameObject> grounds = PlayController.main.GetTerrainHandler().GetGrounds(); float _randomScale = Utils.RandomRange(1.25f, 1.75f); float _randomHeight = Utils.RandomRange(7.0f, 10.0f); foreach (GameObject g in grounds) { Vector3 newPos = g.transform.localPosition; float _x = newPos.x; float _z = newPos.z; float xCoord = _x / _randomHeight * _randomScale; float yCoord = _z / _randomHeight * _randomScale; float height = Mathf.PerlinNoise(xCoord, yCoord); newPos.y = height; GroundHandler groundHandler = g.GetComponent <GroundHandler>(); float duration = 0.25f; float _randomDelayX = Utils.RandomRange(0.02f, 0.04f); float _randomDelayY = Utils.RandomRange(0.02f, 0.04f); float delay = _x * _randomDelayX + _z * _randomDelayY; groundHandler.PlayEnter(newPos.y, Mathf.FloorToInt(height * 10f), duration, delay); PlayController.main.GetGridController().AddGridPosition(newPos); } }
private void OnMouseDown() { GameObject buildPrefabObject = PlayController.main.GetBuildPrefabObject(); if (buildPrefabObject != null) { // TODO: Try a building pool // buildingObject = PlayController.main.FetchBuilding(); buildingObject = Instantiate(buildPrefabObject); buildingObject.transform.SetParent(transform); buildingObject.transform.localPosition = Vector3.zero; PlayController.main.HandleBuildingSpawned(buildingObject); PlayController.main.GetGridController().SliceGridPosition(transform.localPosition); PlayController.main.UpdateResourceCosts(buildingObject); PlayController.main.DestroyFollowObject(); List <GameObject> grounds = PlayController.main.GetTerrainHandler().GetGrounds(); // play anims float duration = 0.05f; float delay = 0.15f; PlayBuildAnimation(duration, 0f); foreach (GameObject g in grounds) { float _x = transform.localPosition.x; float _z = transform.localPosition.z; float space = 2f; if (g.transform.localPosition.x == _x && g.transform.localPosition.z == _z + space) { GroundHandler gh = g.GetComponent <GroundHandler>(); gh.PlayBuildAnimation(duration, delay); } if (g.transform.localPosition.x == _x && g.transform.localPosition.z == _z - space) { GroundHandler gh = g.GetComponent <GroundHandler>(); gh.PlayBuildAnimation(duration, delay); } if (g.transform.localPosition.x == _x + space && g.transform.localPosition.z == _z) { GroundHandler gh = g.GetComponent <GroundHandler>(); gh.PlayBuildAnimation(duration, delay); } if (g.transform.localPosition.x == _x - space && g.transform.localPosition.z == _z) { GroundHandler gh = g.GetComponent <GroundHandler>(); gh.PlayBuildAnimation(duration, delay); } } } }
public List <GameObject> Load() { grounds.Clear(); for (int childIndex = 0; childIndex < transform.childCount; ++childIndex) { GameObject child = transform.GetChild(childIndex).gameObject; if (child.GetComponent <GroundHandler>() != null) { GroundHandler groundHandler = child.GetComponent <GroundHandler>(); groundHandler.Load(transform); grounds.Add(child); } } return(grounds); }