The problem here is that using WaitForSeconds does not cause the method to loop… It just pauses within the method call:
IEnumerator Example(){
//do something
yield return new WaitForSeconds(1);
//do a second thing after one second
}// The end
In your example, the yield is pointless, since nothing happens after it…
Second, you are simply moving your main camera to the position of your other camera, not switching cameras as stated… Let’s start with the simplest possible method, to as you put it “just snap” to the other camera:
void OnGUI(){
if(!next_Btn){
Debug.LogError("Please assign a texture on the inspector");
return;
}
if(GUI.Button(new Rect(10,10,50,50), next_Btn))
{
Debug.Log("Clicked the button. Yippee...");
camera_Mgr.cameraOne = !camera_Mgr.cameraOne;
}
}
And the camera script:
public boolean cameraOne = true;
public Camera main_Camera;
public Camera second_Camera;
void Update(){
if(cameraOne){
main_Camera.enabled = true;
second_Camera.enabled = false;
}
else{
main_Camera.enabled = false;
second_Camera.enabled = true;
}
}
By toggling a variable (cameraOne) , we are making the current camera state easily available… then we just check cameraOne and turn on the appropriate camera (based on whether it is true or false).
This will also make the lerping thing easy, since we can just use Update()…
camera script version 2:
public boolean cameraOne = true;
public Transform positionA; // you could just use an empty GameObject for these
public Transform positionB; // a camera will work too, but it's less efficient
private Transform target;
public Camera main_Camera;
void Update(){
float duration = Time.deltaTime*3;
Vector3 pos = main_Camera.transform.position;
Quaternion rot = main_Camera.transform.rotation;
if(cameraOne)
target = positionA;
else
target = positionB;
main_Camera.transform.position = Vector3.Lerp(pos, target.position, duration);
main_Camera.transform.rotation = Quaternion.Lerp(rot, target.rotation, duration);
}
for fading between cameras, maybe have a look at this:
http://wiki.unity3d.com/index.php?title=CrossFadePro