how to put in function any variables? like object?

using UnityEngine;
using System.Collections;

public struct UpdateYield {
	public float time;
	public float time1;
	
	public object Compare2;
	
	public bool UWaitForSecondsF (object Compare1, float YieldTime){
		Debug.Log("in the function");
		if (Compare2 != Compare1){
			Debug.Log("Changing compare 2");
			Compare2 = Compare1;
			time = Time.time;
			return false;
		}
		time1 = Time.time;
		// if it's X seconds same return true
		if (((time1 - time) > YieldTime) && Compare1 == Compare2){
			return true;
		}
		return false;
	}
}

// testing
public UpdateYield asdf;

void Update () {
bool bah = asdf.UWaitForSecondsF(5, 3);
if (bah){Debug.Log("yield time works");}
}

when I change both objects in to floats the code works

	object Compare2; -- > float Compare2

how should I change my code that I could put anything inside and that it won’t think all the time it’s not same IF it hasn’t been changed?

I know I could use coroutine but there are 1-3 ocasions I cannot do that in my code

and would like less thinking and more doing

The answer to your question would be Generic Methods.

For comparing purposes, you can do something like this:

public bool Same<T>( T a, t b ) {
   return ( a == b );
}

You will then use this as:

bool sameString = Same<string>("aaa", "abc");
bool sameInt = Same<int>(10, (5*2));
bool sameTransform = Same<Transform>( transform, gameObject.transform);

But you need to do a little bit more work to incorporate it into your script, I am just giving you a direction here.

C# Generic Method

got it

using UnityEngine;
using System.Collections;

public struct UpdateYield {
	private float time;
	private float time1;
	
	private object Compare2;
	
	public bool UWaitForSecondsF (object Compare1, float YieldTime){
		//Debug.Log("in the function");
		if (! Compare1.Equals(Compare2)){
			//Debug.Log("Changing compare 2");
			Compare2 = Compare1;
			time = Time.time;
			return false;
		}
		time1 = Time.time;
		// if it's X seconds same return true
		if (((time1 - time) > YieldTime) && Compare1.Equals(Compare2)){
			return true;
		}
		return false;
	}
}