public void FocusCameraOnPoint(Vector3 center, float time = 1f, CameraId camId = CameraId.main, float height = 0) { if (height == 0) { height = camOrigHeight; } Camera camObj = camMain.GetComponent <Camera>(); CrossControl focalPoint = crossMain; switch (camId) { case CameraId.main: camObj = camMain.GetComponent <Camera>(); focalPoint = crossMain; break; case CameraId.left: camObj = camP1.GetComponent <Camera>(); if (pl1.position.x < pl2.position.x) { focalPoint = crossP1; } else { focalPoint = crossP2; } break; case CameraId.right: camObj = camP2.GetComponent <Camera>(); if (pl1.position.x < pl2.position.x) { focalPoint = crossP2; } else { focalPoint = crossP1; } break; default: Debug.Log("Unrecognized CameraId in CameraSupervisor.FocusCameraOnPoint"); break; } focalPoint.ForceFocus(center); var oldPos = camObj.transform.position; center.z = -(height * 0.5f / Mathf.Tan(camObj.fieldOfView * 0.5f * Mathf.Deg2Rad)); camMain.transform.position = center; addDelayedExecution(time, new DelayedExecution( () => { camObj.transform.position = new Vector3(camObj.transform.position.x, camObj.transform.position.y, oldPos.z); focalPoint.ForceFocus(null); })); }
// Use this for initialization void Start() { if (GameObject.FindGameObjectWithTag("Pl1") != null) { pl1 = GameObject.FindGameObjectWithTag("Pl1").transform; } if (GameObject.FindGameObjectWithTag("Pl2") != null) { pl2 = GameObject.FindGameObjectWithTag("Pl2").transform; } if (GameObject.FindGameObjectWithTag("MainCamera") != null) { camMain = GameObject.FindGameObjectWithTag("MainCamera"); } if (GameObject.FindGameObjectWithTag("CameraP1") != null) { camP1 = GameObject.FindGameObjectWithTag("CameraP1"); } if (GameObject.FindGameObjectWithTag("CameraP2") != null) { camP2 = GameObject.FindGameObjectWithTag("CameraP2"); } if (GameObject.FindGameObjectWithTag("CrossMain") != null) { crossMain = GameObject.FindGameObjectWithTag("CrossMain").GetComponent <CrossControl>(); } if (GameObject.FindGameObjectWithTag("CrossP1") != null) { crossP1 = GameObject.FindGameObjectWithTag("CrossP1").GetComponent <CrossControl>(); } if (GameObject.FindGameObjectWithTag("CrossP2") != null) { crossP2 = GameObject.FindGameObjectWithTag("CrossP2").GetComponent <CrossControl>(); } camMain.GetComponent <Camera>().enabled = true; camP1.GetComponent <Camera>().enabled = false; camP2.GetComponent <Camera>().enabled = false; crossMain.curMode = modes.FollowBoth; crossP1.curMode = modes.FollowBoth; crossP2.curMode = modes.FollowBoth; camOrigHeight = 2.0f * Math.Abs(camMain.transform.position.z) * Mathf.Tan(camMain.GetComponent <Camera>().fieldOfView * 0.5f * Mathf.Deg2Rad); origWidth = camOrigHeight * camMain.GetComponent <Camera>().aspect; camStartY = camMain.transform.position.y; camBaseZ = camMain.transform.position.z; //FocusCameraOnPoint(new Vector3(-22f, -2.5f, 0f), 2); }
// Use this for initialization void Start() { if (GameObject.FindGameObjectWithTag("Pl1") != null) { pl1 = GameObject.FindGameObjectWithTag("Pl1").transform; } if (GameObject.FindGameObjectWithTag("Pl2") != null) { pl2 = GameObject.FindGameObjectWithTag("Pl2").transform; } if (GameObject.FindGameObjectWithTag("MainCamera") != null) { camMain = GameObject.FindGameObjectWithTag("MainCamera"); } if (GameObject.FindGameObjectWithTag("CameraP1") != null) { camP1 = GameObject.FindGameObjectWithTag("CameraP1"); } if (GameObject.FindGameObjectWithTag("CameraP2") != null) { camP2 = GameObject.FindGameObjectWithTag("CameraP2"); } if (GameObject.FindGameObjectWithTag("CrossMain") != null) { crossMain = GameObject.FindGameObjectWithTag("CrossMain").GetComponent <CrossControl>(); } if (GameObject.FindGameObjectWithTag("CrossP1") != null) { crossP1 = GameObject.FindGameObjectWithTag("CrossP1").GetComponent <CrossControl>(); } if (GameObject.FindGameObjectWithTag("CrossP2") != null) { crossP2 = GameObject.FindGameObjectWithTag("CrossP2").GetComponent <CrossControl>(); } camMain.GetComponent <Camera>().enabled = true; camP1.GetComponent <Camera>().enabled = false; camP2.GetComponent <Camera>().enabled = false; camMain.GetComponent <Camera>().orthographicSize = defaultCamSize; camP1.GetComponent <Camera>().orthographicSize = defaultCamSize; camP2.GetComponent <Camera>().orthographicSize = defaultCamSize; crossMain.curMode = modes.FollowBoth; crossP1.curMode = modes.FollowBoth; crossP2.curMode = modes.FollowBoth; camStartY = camMain.transform.position.y; }