How to make obect move only if its on top of another object

I am instantiating some objects in my scene so they fall onto another compound object (object made up of several parts) I want it so the objects move negatively along the z axis, but only if its touching the compound object. I have done some research on this but all I can find is raycasting to see if the object is touching the ground, however (maybe its just me because i’m not that experienced) but I cant seem to get that to work. I use c#. thanks for your help in advance.

EDIT: This is the code I am using to instantiate my objects.

void Update()
{

	pennySpawn -= Time.deltaTime;
	dimeSpawn -= Time.deltaTime;
	nickelSpawn -= Time.deltaTime;

	Quaternion rotation = rotationRot;
	
	if (pennySpawn <= 0 && amountPenniesAllowed <= penniesAllowed && coins <= coinsAllowed) 
	{
		Instantiate(penny, new Vector3(Random.Range (-3.0f, 3.0f), 1.5F, Random.Range (5.0f, 15.0f)), rotation);
		pennySpawn = 1.0f;
		pennySpawn -= Time.deltaTime;
		amountPenniesAllowed = amountPenniesAllowed + 1;
		coins = coins + 1;
	}

	if (dimeSpawn <= 0 && amountDimesAllowed <= dimesAllowed && coins <= coinsAllowed) 
	{
		Instantiate(dime, new Vector3(Random.Range (-3.0f, 3.0f), 1.5F, Random.Range (5.0f, 15.0f)), rotation);
		dimeSpawn = 1.4f;
		dimeSpawn -= Time.deltaTime;
		amountDimesAllowed = amountDimesAllowed + 1;
		coins = coins + 1;
	}

	if (nickelSpawn <= 0 && amountNickelsAllowed <= nickelsAllowed && coins <= coinsAllowed) 
	{
		Instantiate(nickel, new Vector3(Random.Range (-3.0f, 3.0f), 1.5F, Random.Range (5.0f, 15.0f)), rotation);
		nickelSpawn = 1.2f;
		nickelSpawn -= Time.deltaTime;
		amountNickelsAllowed = amountNickelsAllowed + 1;
		coins = coins + 1;
	}

Have you tried to check if he is on the floor by checking if its colliding with the floor? And if its collides then it can move?

Add an OnCollisionStay function to a component on the coins (Unity - Scripting API: Collider.OnCollisionStay(Collision)).

Inside OnCollisionStay do something like this:

public Collider GroundCollider;
public float Speed = 1.0f;

void OnCollisionStay(Collision collisionInfo) 
{
	if ( collisionInfo.collider == GroundCollider )
	{
		transform.position += Vector3.forward * Time.deltaTime * Speed;
	}
}

Then in the editor set the GroundCollider property to whatever collider they’re going to land on.