// Use this for initialization void Start() { mouseQueue = new Queue <Vector2>(Enumerable.Repeat <Vector2>(Vector2.zero, mouseQueueCount)); mouse_multiplier = 100; controller_multiplier = 50; mouse_sensitivity = 2 * Vector2.one; controller_sensitivity = new Vector2(6, 3); //target_follow_distance = new Vector3(0f, 0.4f, -1f); //target_follow_angle = new Vector3(14f, 0f, 0f); pivot = new GameObject("pivot"); PlayerControllerSource player_home = home.GetComponent <PlayerControllerSource>(); if (player_home == null) { throw new Exception("Failed initializing camera."); } // Move pivot to target MovePivotToTarget(home); // Attach the camera to the pivot and set the default distance/angles transform.parent = pivot.transform; transform.localPosition = target_follow_distance; transform.localRotation = Quaternion.Euler(target_follow_angle); Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; }
// Jump to a game object that has a player controller private void MovePivotToTarget(GameObject target) { PlayerControllerSource player = target.GetComponent <PlayerControllerSource>(); if (player == null) { Debug.Log("Failed to move to player"); return; } if (current_player != null) { current_player.player_camera = null; } pivot.transform.parent = target.transform; pivot.transform.localPosition = Vector3.zero; player.player_camera = controlled_camera; current_player = player; }