IEnumerator ConstructFloor() { GameObject floorObject = Instantiate(floorModel, Vector3.zero, Quaternion.identity, myTransform); floorObject.name = string.Concat("Floor", floors.Count); Floor floor = floorObject.GetComponent <Floor>(); floor.floorIndex = floors.Count; floor.myTransform.localPosition = Vector3.zero; floors.Add(floor); floor.myTransform.SetParent(TowerBase); for (int i = 0; i < objectNumberPerFloor; i++) { GameObject part = Instantiate(model, Vector3.zero, Quaternion.identity, myTransform); part.name = string.Concat("TowerPart", floors.Count * objectNumberPerFloor + i); TowerPart towerPart = part.GetComponent <TowerPart>(); towerPart.myTransform.localEulerAngles = Vector3.zero; towerPart.myTransform.localPosition = new Vector3(0f, model.transform.lossyScale.y, neededRadius); towerPart.myTransform.SetParent(floor.myTransform); //color the towerPart int randomSelectedColorIndex = MyEventSystem.instance.Get("GetRandomSelectedColorIndex"); towerPart.SetInitialMaterial(MyEventSystem.instance.Get("selectedTowerPartMaterials")[randomSelectedColorIndex]); yield return(new WaitForSeconds(buildDelay)); myTransform.eulerAngles += Vector3.up * angleStep; } floor.AddToFloor(floor.myTransform.GetComponentsInChildren <TowerPart>()); }
public void TowerPartDestructed(TowerPart part) { towerPartsStillOnThatFloor.Remove(part.gameObject); if (towerPartsStillOnThatFloor.Count == 0 && !empty) { empty = true; MyEventSystem.instance.FireEvent("EmptyFloor"); } }
void ScoreUpdate(string name, GenericDictionary args) { TowerPart part = args.Get("DestructedTowerPart"); foreach (Floor floor in towerConstructor.floors) { floor.TowerPartDestructed(part); } }
private void OnCollisionEnter(Collision collision) { if (!isRespawning) { if (collision.gameObject.CompareTag("TowerPart")) { TowerPart towerPart = collision.gameObject.GetComponent <TowerPart>(); //if it's a valid towerpart destroy the group and respawn ball if (towerPart.myColor == myRenderer.material.color && !towerPart.myRigidbody.isKinematic) { towerPart.GroupDestruction(); //respawn management BallRespawn(); } else { myCollider.enabled = false; //choose a random zone outside of the screen float distancewithZ0 = Vector3.Distance(outOfScreenZones[0].position, ball.position); float distanceWithZ1 = Vector3.Distance(outOfScreenZones[1].position, ball.position); Transform outOfScreenRandomSelectedZone = outOfScreenZones[0]; //we are at equal distance from the two zone, select one randomly if (Mathf.Abs(distancewithZ0 - distanceWithZ1) <= 0.05f) { outOfScreenRandomSelectedZone = outOfScreenZones[Random.Range(0, outOfScreenZones.Count)]; } else if (distancewithZ0 > distanceWithZ1) { outOfScreenRandomSelectedZone = outOfScreenZones[1]; } Vector3 destination = new Vector3(outOfScreenRandomSelectedZone.position.x, ball.position.y + Random.Range(-2f, 2f), outOfScreenRandomSelectedZone.position.z); DOTween.Kill("Throwing"); DOTween.Kill("Rebound"); ball.DOMove(destination, throwDuration).SetEase(throwEase).OnComplete(BallRespawn).SetId("Rebound"); } } } }