private void OnDisable() { //EditorApplication.update -= UpdatePreview; CleanupTemp(); if (PortalController && PortalController.TargetController) { PortalController.TargetController.CleanupTemp(); } //DestroyImmediate(_matEditor, true); if (Application.isPlaying) { return; } if (PortalController) { PortalController.GetComponent <Renderer>().enabled = true; } if (PortalController) { PortalController.GetComponent <Renderer>().sharedMaterial.color = PortalController.color; } }
void CreatePortal(GameObject collidedWall) { GameObject g = Instantiate(portalPrefab, collidedWall.transform.position, Quaternion.identity); if (nextPortal == PortalType.Red) { if (redPortal != null) { Destroy(redPortal.gameObject); } redPortal = g.GetComponent <PortalController>(); redPortal.InitPortal(throwingDirection, ref collidedWall, PortalType.Red); if (bluePortal == null) { redPortal.GetComponent <Animator>().speed = 0f; } else { bluePortal.GetComponent <Animator>().speed = 1f; } nextPortal = PortalType.Blue; } else if (nextPortal == PortalType.Blue) { if (bluePortal != null) { Destroy(bluePortal.gameObject); } bluePortal = g.GetComponent <PortalController>(); bluePortal.InitPortal(throwingDirection, ref collidedWall, PortalType.Blue); if (redPortal == null) { bluePortal.GetComponent <Animator>().speed = 0f; } else { redPortal.GetComponent <Animator>().speed = 1f; } nextPortal = PortalType.Red; } //g.transform.SetParent(trans, false); PortalController portalController = g.GetComponent <PortalController>(); BoxCollider portalCollider = g.GetComponent <BoxCollider>(); portalCollider.size = new Vector3(0.9f, 0.1f, 0); portalCollider.center = new Vector3(0, 0.2f, 0); switch (throwingDirection) { case GameController.Direction.Up: break; case GameController.Direction.Down: Vector3 rotD = g.transform.rotation.eulerAngles; rotD = new Vector3(rotD.x, rotD.y, rotD.z + 180); g.transform.rotation = Quaternion.Euler(rotD); break; case GameController.Direction.Right: Vector3 rotR = g.transform.rotation.eulerAngles; rotR = new Vector3(rotR.x, rotR.y, rotR.z - 90); g.transform.rotation = Quaternion.Euler(rotR); break; case GameController.Direction.Left: Vector3 rotL = g.transform.rotation.eulerAngles; rotL = new Vector3(rotL.x, rotL.y, rotL.z + 90); g.transform.rotation = Quaternion.Euler(rotL); break; } }