// Update is called once per frame void Update() { try { spawner = GameObject.Find("BirbSpawner").GetComponent <SpawnerController>(); player = spawner.getBirb(); } catch (Exception e) { Debug.LogError("Could not find any GameObject with the Tag \"player\"", this); Debug.LogException(e, this); Debug.Log("CameraFollow is turning off to prevent further issues.", this); //enabled = false; } focus = player.transform.position; float leftSnap = transform.position.x - screenWidth * CAMERA_SNAP; float leftThreshold = transform.position.x - screenWidth * CAMERA_THRESHOLD; //Debug.DrawLine(new Vector3(leftSnap, transform.position.y, 0), new Vector3(leftSnap, transform.position.y + 5, 0), Color.blue); //Debug.DrawLine(new Vector3(leftThreshold, transform.position.y, 0), new Vector3(leftThreshold, transform.position.y + 5, 0), Color.blue); float rightSnap = transform.position.x + screenWidth * CAMERA_SNAP; float rightThreshold = transform.position.x + screenWidth * CAMERA_THRESHOLD; //Debug.DrawLine(new Vector3(rightSnap, transform.position.y, 0), new Vector3(rightSnap, transform.position.y + 5, 0), Color.blue); //Debug.DrawLine(new Vector3(rightThreshold, transform.position.y, 0), new Vector3(rightThreshold, transform.position.y + 5, 0), Color.blue); Debug.Log("player: " + player); if (leftRoomBounds < player.transform.position.x - screenWidth && rightRoomBounds > player.transform.position.x + screenWidth) { if (boundTransitioning == null) { if (currentSnap == SnapBound.Left) { if (player.transform.position.x > leftSnap) { focus.x = player.transform.position.x + (transform.position.x - leftSnap); } else if (player.transform.position.x < leftThreshold) { currentSnap = SnapBound.Right; boundTransitioning = StartCoroutine(BoundTransition()); } } else { if (player.transform.position.x < rightSnap) { focus.x = player.transform.position.x - (rightSnap - transform.position.x); } else if (player.transform.position.x > rightThreshold) { currentSnap = SnapBound.Left; boundTransitioning = StartCoroutine(BoundTransition()); } } } } focus.y = player.transform.position.y; focus.z = -20; transform.position = focus; }
// Initialization void Start() { screenWidth = Camera.main.orthographicSize * Screen.width / Screen.height; currentSnap = SnapBound.Left; }