Issues with switching cameras

Heya,

I’m currently making a little script that allows me to switch between 2 camera’s (well, actually just one, but I’m enabling and disabling the first- and third-person scripts.)

The scene starts with a first person view. When I scroll (zoom out) I get a third person view. The first transition is flawless, but when I try this a second time the camera does weird things (it starts flying around or it stays right above my character,…). I have tried numerous things, like placing the camera at the player’s position. But nothing seems to work.

The following is my messed up script, hope you can figure it out…

public class CameraSwitch : MonoBehaviour {

public float Zoom = 0F;

public Transform Target;

private Vector3 PlayerPosition;

private bool ResetThirdPersonPos;


// Use this for initialization
void Start () 
{
	PlayerPosition = (Vector3)GameObject.FindGameObjectWithTag("MainCamera").transform.position - (Vector3)GameObject.FindGameObjectWithTag("Player").transform.position;
}

// Update is called once per frame
void Update () 
{		
	ZoomFirstToThird();
}	
	
void ZoomFirstToThird()
{
	Zoom -= (Input.GetAxis("Mouse ScrollWheel"));
	
	if (Zoom < 0)
	{
		Zoom = 0;			
	}
	
	if (Zoom == 0)
	{
		GetComponent<MouseLook>().enabled = true;
		GetComponent<SmoothFollow>().enabled = false;
		if (ResetThirdPersonPos == false)
		{
			this.transform.Translate(PlayerPosition,GameObject.FindGameObjectWithTag("MainCamera").transform);
			ResetThirdPersonPos = true;
		}
		
	}
	
	if (Zoom > 0)
	{
		GetComponent<SmoothFollow>().enabled = true;
		GetComponent<MouseLook>().enabled = false;
		ResetThirdPersonPos = false;
	}
}

EDIT: clarified the ‘weird things’ bit.

if (Zoom == 0) is dangerous for float vars. Use Mathf.Approximately http://unity3d.com/support/documentation/ScriptReference/Mathf.Approximately.html

Just guessing but you might need to reset zoom = 0.0 before the ‘second time’