Lapsed values

I have a value that is being updated inside my Update() function.

I need to pick a value and after some time, compare with the current one.

    void Start()
    {
        prevValue = 0;
        InvokeRepeating("checkValue", 0, 0.5f);
    }
    void checkValue()
    {
        if (Mathf.Abs(prevValue - currentValue) > 10)
            Debug.Log("Ok");
        
        prevAttitude = attitude;
    }

I don’t know why, but it’s not working properly. Any other idea about how to make this?

Cheers!

Hm, you mean something like this? The following script works just fine for me, so you must have something going on somewhere else in your code…

using UnityEngine;
using System.Collections;

public class testScript : MonoBehaviour {
	
	float timeMe;
	
	void Start () 
	{
		InvokeRepeating("checkRepeat", 0, 0.5f);
	}
	
	void Update ()
	{
		timeMe = Time.time;
	}
	
	void checkRepeat()
	{
		if (timeMe >= 5)
			Debug.Log ("This has gone on more than 5 seconds");
	}
}

I’ve just discovered that the problem was not in my code, it is in the variable.