private void UpdateCameraFollowing() { for (int i = 0; i < following_items.Count; ++i) { CameraFollowItem curr_item = following_items[i]; float movement_time = curr_item.GetMovementTime(); Vector3 offset = curr_item.GetOffset(); Camera camera = curr_item.GetCamera(); Transform following_trans = curr_item.GetFollowingGameObject().transform; Vector3 desired_pos = following_trans.position + offset; Vector3 smoothed_position = Vector3.SmoothDamp(camera.transform.position, desired_pos, ref curr_item.velocity, movement_time); if (!camera.orthographic) { camera.transform.position = smoothed_position; } else { camera.transform.position = new Vector3(smoothed_position.x, smoothed_position.y, camera.transform.position.z); } } }
public void CameraFollow(Camera camera, GameObject go, float movement_time, Vector3 offset) { if (go != null && camera != null) { CameraStopFollow(camera); CameraFollowItem item = new CameraFollowItem(camera, go, movement_time, offset); following_items.Add(item); } }
public void CameraUpdateFollow(Camera camera, float movement_time, Vector3 offset) { for (int i = 0; i < following_items.Count; ++i) { CameraFollowItem curr_item = following_items[i]; if (curr_item.GetCamera() == camera) { curr_item.SetMovementTime(movement_time); curr_item.SetOffset(offset); } } }
public void CameraStopFollow(Camera camera) { for (int i = 0; i < following_items.Count; ++i) { CameraFollowItem curr_item = following_items[i]; if (curr_item.GetCamera() == camera) { following_items.RemoveAt(i); break; } } }
public void CamerasStopFollow(GameObject go) { for (int i = 0; i < following_items.Count;) { CameraFollowItem curr_item = following_items[i]; if (curr_item.GetFollowingGameObject() == go) { following_items.RemoveAt(i); } else { ++i; } } }