Why is i never equal to an amount?

This is the code I use for my Camera movement:

using UnityEngine;
using System.Collections;



public enum CameraState
{
    CameraGoUp,
    CameraGoDown,
    CameraStandard
}
[RequireComponent(typeof(Camera))]
public class CameraBehaviour : MonoBehaviour {

	public GameObject player;
    public CameraState cameraState = CameraState.CameraStandard;
    private float cameraX;
    private float cameraZ;
    private float cameraY;
    private float currentY;
    private float i;
    public float riseAmount = 10;
    public float fallAmount = 10;
    public float riseSpeed = 0.1F;
    public float fallSpeed = 0.1F;

    void Update()
    {
        currentY = transform.position.y;
        CameraMovement();
    }

    void LateUpdate()
    {
        DetermineCoordinates(player.transform.position.x, player.transform.position.z);
        Vector3 cameraTransform = new Vector3 (cameraX, cameraY,cameraZ);
        transform.position = cameraTransform;
        IReset();
    }

    private void DetermineCoordinates(float playerX, float playerZ)
    {
        cameraX = playerX + 30;
        cameraZ = playerZ - 10;
        cameraY = currentY;
    }

    private void CameraMovement()
    {
        switch (cameraState)
        {
            case CameraState.CameraGoUp:
                if (i < riseAmount)
                {
                    currentY = currentY + riseSpeed;
                    Debug.Log("Camera is moving up");
                    i = i + riseSpeed;
                }
                break;
            case CameraState.CameraGoDown:
                if (i < fallAmount)
                {
                    currentY = currentY - fallSpeed;
                    Debug.Log("Camera is moving down");
                    i = i + fallSpeed;
                }
                break;
            case CameraState.CameraStandard:
                break;
        }
    }

    private void IReset()
    {
        if (i != riseAmount)
        {
            Debug.Log("i is not riseAmount");
        }
        if (i == riseAmount)
        {
            Debug.Log("i is riseAmount");
            i = 0;
            Debug.Log("i has been reset!");
            cameraState = CameraState.CameraStandard;
        } else if (i == fallAmount)
        {
            Debug.Log("i is fallAmount");
            i = 0;
            Debug.Log("i has been reset!");
            cameraState = CameraState.CameraStandard;
        }
    }
}

Now, this is what triggers the movement:

    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("CameraMoveUp"))
        {
            cameraMoveUp = other.gameObject.GetComponent<CameraMoveUp>();
            cameraBehaviour.riseAmount = cameraMoveUp.riseAmount;
            cameraBehaviour.cameraState = CameraState.CameraGoUp;
        } else if (other.gameObject.CompareTag("CameraMoveDown"))
        {
            cameraMoveDown = other.gameObject.GetComponent<CameraMoveDown>();
            cameraBehaviour.fallAmount = cameraMoveDown.fallAmount;
            cameraBehaviour.cameraState = CameraState.CameraGoDown;
        }
    }

The problem with this system is that, for some reason, i is never reset to 0 because it is apparently never equal to rise- or fallAmount. I’ve checked in the inspector’s debug mode though, and it says that:

I = 10

Rise Amount = 10

Fall Amount = 10

So why is it not resetting i?
i obviously has the exact same value as the other two.

Help is greatly appreciated, since this means that I can only move the camera once per scene.

If you’re sure that your logic works as expected and you’re really getting “equal” numbers, you still cannot safely compare floats with ==. Floats are never exactly some number, as the name suggests, they can shift up and down a tiny amount. Therefore you should either compare with >= and <= to define a range or if you are pretty sure, that you actually reach your desired value, you can compare with Mathf Approximately.

Floating point errors are happening. You can’t really ever guarantee that a float will be equal to some value after doing calculations with it.

If you need exact numbers, you’d be better off using ints. If you can’t (and need floating point numbers), you could always cast the float to an int (however that will get rid of all numbers past the decimal and give you an integer value).