Hi everybody, How can I switch the player view from one camera to another. I have tried the following way: Code (csharp): GameObject.Find("Initial Camera").GetComponent("Camera").active = false; GameObject.Find("Main Camera").GetComponent("Camera").active = true; and is not working. Any ideas will be welcomed. Thanks.
digitalwm, I'm not sure why yours isn't working. Here is what I am using: Code (csharp): GameObject _cameraFP = null; GameObject _cameraWV = null; void Start () { // Init camera _cameraFP = GameObject.Find("Main Camera"); if (_cameraFP == null) Debug.Log("Start(): First Person Camera not found"); _cameraWV = GameObject.Find("Main Camera Wide View"); if (_cameraWV == null) Debug.Log("Start(): Wide View Camera not found"); } void SelectCamera(int cameraIndex) { if (_cameraFP != null) _cameraFP.camera.enabled = (cameraIndex == 0); if (_cameraWV != null) _cameraWV.camera.enabled = (cameraIndex == 1); } Hope that helps, -Chris
where do you put this and how do you use it? on a camera or the main camera or the player not sure. and how to you make it switch, through a getkeydown or soemthing like that? thanks
You can put this anywhere convenient, say on an empty object somewhere in the scene acting as a camera controller. You can use any event you like to switch cameras, so it could be a keystroke, but could just as easily be an event in the game.
i tried Code (csharp): GameObject.Find("InitialCamera").GetComponent("Camera").active = false; GameObject.Find("MainCamera").GetComponent("Camera").active = true; and it worked for me. dont know what you could have done different then me.
probably he has a third (or first) person controller where in somewhere is calling the Camera.main.transform... i guess..