private void OnTriggerEnter2D(Collider2D collision) { if (target != null && !travellers.Contains(collision.gameObject) && !isDying) { Camera_Behaviour cam = Camera.main.GetComponent <Camera_Behaviour>(); Vector3 pPos; if (cam.player) { pPos = cam.player.transform.position; } else { pPos = cam.transform.position; } // Teleport collision.transform.position = target.transform.position; var tar = target.GetComponent <Wormhole_Behavior>(); // Has player teleported bool playerTP = (cam.player != null && pPos != cam.player.transform.position); // Other side is wormhole if (tar) { tar.travellers.Add(collision.gameObject); var planet = collision.gameObject.GetComponent <Planet_Behavior>(); if (planet) { // Set new orbit planet.orbitPoint = tar.orbitPoint; if (inverteRotation) { planet.orbitSpeed = -planet.orbitSpeed; planet.rotationSpeed = -planet.rotationSpeed; } } } if (playerTP) { if (shouldShake) { StartCoroutine(cam.SetScreenshake()); } if (singleTicket || (tar && tar.singleTicket)) { Disappear(); if (tar) { tar.Disappear(); } } } } }
/************************************************************************************************* * Function: void Awake() * Description: Runs at initialization of script. * If player fade disabled, disables scene fade by default so that scene can't * fade in without a player and instead scene will start without any fading (Not * fixing this situation would result in scene fading in without visible player * and with player controls disabled so user couldn't do anything). If scene fade * enabled, initializes fader Image to black and full screen, else disables fader. ************************************************************************************************/ void Awake() { scene_manager = GetComponent <Scene_Manager> (); player = Instantiate(player_prefab, start.position, Quaternion.Euler(0, 0, get_start_rotation())) as GameObject; player.transform.position = get_start_position(); player_renderer = player.GetComponent <SpriteRenderer> (); player_controller = player.GetComponent <Player> (); player_controller.start_facing_right = start_facing_right; player_controller.set_spawn(player.transform, get_start_gravity_direction()); main_cam_script = Camera.main.GetComponent <Camera_Behaviour>(); main_cam_script.set_target(player.transform); }