Try this on for size. One warning: do not just cut and paste this code, as it will probably not work the way you expect it to work (if it works at all). Please try to study it before using it.
# Assign your color here.
var color
func _physics_process(change):
if some_raycast.is_colliding():
var le_collider = some_raycast.get_collider()
# Check if "le_collider" is of the same class as the grass (or dirt, or metal, or rock, or...) block. For this example, we'll assume it's a TileMap.
if le_collider is TileMap:
# Now check to see if the TileMap is in the "Ground" group (or whatever group you want to place these blocks in).
if le_collider.is_in_group("Ground"):
# Check for which block is being used. How do you do this? That's up to you. Here, I'll match names. Side note: isn't this starting to look like an "if" arrow?
match le_collider.get_name():
"grass":
color = "green"
"ground":
color = "brown"
"metal":
color = "silver"
_:
# Couldn't figure out the color. Print an error and exit.
push_error("Couldn't determine block color.")
get_tree().quit()
# Now assign the color. How you do that is up to you. The following function is made up.
set_particle_color(color)