public void switchCameraBoundsBetweenRegion(int part) { CameraController camController = camObject.GetComponent <CameraController>(); ScenePartLoader loader = GameObject.Find(GetSceneName()).GetComponent <ScenePartLoader>(); camController.border = loader.regions[part]; regionPart = part; camController.updateBorder(); }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.CompareTag("RegionCameraSwitcher")) { r_AttackController.resetThrowingVars(); ScenePartLoader loader = GameObject.Find(manager.GetSceneName()).GetComponent <ScenePartLoader>(); } if (collision.gameObject.CompareTag("Enemy")) { isTouchedEnemy = true; } }
public void setCameraBounds(int sceneNumber) { previousSceneNumber = currentSceneNumber; currentSceneNumber = sceneNumber; CameraController camController = camObject.GetComponent <CameraController>(); GameObject ob = GameObject.Find(GetSceneName()); ScenePartLoader loader = ob.GetComponent <ScenePartLoader>(); Collider2D closestCollider; if (loader.regions.Length > 1) { Collider2D[] colliders = new Collider2D[2]; colliders[0] = loader.regions[0].GetComponent <Collider2D>(); colliders[1] = loader.regions[1].GetComponent <Collider2D>(); closestCollider = colliders[0]; Vector3 closestPointB = closestCollider.ClosestPoint(playerController.transform.position); float distanceB = Vector3.Distance(closestPointB, playerController.transform.position); foreach (Collider2D collider in colliders) { Vector3 closestPointA = collider.ClosestPoint(playerController.transform.position); float distanceA = Vector3.Distance(closestPointA, playerController.transform.position); if (distanceA < distanceB) { closestCollider = collider; distanceB = distanceA; } } } else { closestCollider = loader.regions[0].GetComponent <Collider2D>(); } camController.border = closestCollider.gameObject; int closestPart = 0; if (closestCollider.name == loader.regions[0].name) { closestPart = 0; } else { closestPart = 1; } regionPart = closestPart; camController.updateBorder(); Scene s = SceneManager.GetSceneByBuildIndex(previousSceneNumber); GameObject[] gameObjects = s.GetRootGameObjects(); foreach (GameObject obj in gameObjects) { if (obj.CompareTag("PathFinder")) { obj.SetActive(false); } } s = SceneManager.GetSceneByBuildIndex(currentSceneNumber); gameObjects = s.GetRootGameObjects(); foreach (GameObject obj in gameObjects) { if (obj.CompareTag("PathFinder")) { obj.SetActive(true); } if (currentSceneNumber > 1) { if (obj.name == "EnemySpawner") { obj.GetComponent <EnemyManager>().enabled = true; } } } GameObject.FindGameObjectWithTag("Player").GetComponent <RangedAttackWithTeleportation>().resetThrowingVars(); }