IEnumerator SpawnElectricalPlate_C() { GameObject electricalPlate = Instantiate(bossSettings.electricalPlateSettings.platePrefab, transform); currentElectricalPlate = electricalPlate.GetComponent <PuzzleEletricPlate>(); currentElectricalPlate.Desactivate(); electricalPlate.transform.localScale = new Vector3(1f, 0.1f, 1f); Vector3 startPosition = transform.position + Vector3.down * 5f; Vector3 endPosition = transform.position + Vector3.down * -0.1f; for (float i = 0; i < 1f; i += Time.deltaTime) { electricalPlate.transform.position = Vector3.Lerp(startPosition, endPosition, i / 1f); yield return(null); } yield return(new WaitForSeconds(bossSettings.electricalPlateSettings.duration)); DespawnElectricalPlate(); }
public void ReshapeElectricalPlate(Vector2 _size) { float plateDimension = 6.6f; Transform plateHolder = plate.transform.Find("PlateHolder"); if (plateHolder != null) { DestroyImmediate(plateHolder.gameObject); } GameObject newHolder = new GameObject(); newHolder.name = "PlateHolder"; newHolder.transform.SetParent(plate.transform); newHolder.transform.localPosition = Vector3.zero; newHolder.transform.localScale = Vector3.one; Vector2 plateSize = _size; Vector2 finalSize = new Vector2(plateSize.x * plateDimension, plateSize.y * plateDimension); //Generates plates for (int x = 0; x < plateSize.x; x++) { for (int y = 0; y < plateSize.y; y++) { GameObject newPart = default; if (plateSize.x == 1) { newPart = (GameObject)PrefabUtility.InstantiatePrefab(Resources.Load <GameObject>("PuzzleResource/ElectricalPlate/PlatePart_DoubleSide")); } else if (x == 0 || x == plateSize.x - 1) { newPart = (GameObject)PrefabUtility.InstantiatePrefab(Resources.Load <GameObject>("PuzzleResource/ElectricalPlate/PlatePart_Side")); if (x == plateSize.x - 1) { newPart.transform.localRotation = Quaternion.Euler(new Vector3(0, -180, 0)); } } else { newPart = (GameObject)PrefabUtility.InstantiatePrefab(Resources.Load <GameObject>("PuzzleResource/ElectricalPlate/PlatePart_Center")); } newPart.transform.SetParent(newHolder.transform); newPart.transform.localScale = Vector3.one; newPart.transform.localPosition = new Vector3(y * plateDimension - (finalSize.y / 2f - (plateDimension / 2f)), -0.4f, x * plateDimension - (finalSize.x / 2f - (plateDimension / 2f))); } } //Generates box collider BoxCollider bc = plate.GetComponent <BoxCollider>(); if (bc == null) { bc = plate.gameObject.AddComponent <BoxCollider>(); } bc.size = new Vector3(finalSize.x, 3f, finalSize.y); bc.center = new Vector3(0f, 1f, 0f); bc.isTrigger = true; //Update plate FX list PuzzleEletricPlate plateScript = plate.GetComponent <PuzzleEletricPlate>(); List <GameObject> plateFXParent = new List <GameObject>(); List <ParticleSystem> FXTotalList = new List <ParticleSystem>(); if (plateScript != null) { foreach (Transform t in newHolder.transform) { plateFXParent.Add(t.Find("FX_ElectricPlate").gameObject); } } foreach (GameObject g in plateFXParent) { FXTotalList.Add(g.GetComponent <ParticleSystem>()); foreach (Transform t in g.transform) { FXTotalList.Add(t.GetComponent <ParticleSystem>()); } } plateScript.FXS = FXTotalList; plateScript.indictatorLightsList = new List <Light>(); EditorUtility.SetDirty(plateScript); }