Unable to apply "transform" on gameobject from Raycast

I have 2 blocks, Block A is the player, Block B is part of a cube grid floor. I want to get the position of Block B from Block A. There are many Block Bs in the Scene.

I’m able to destroy the specific Block B the player is above (I’m using forward on the raycast this is correct), but can’t get it’s position. S o Ican zip around deleting the floor as I go, but can’t get the position of any of these game objects :confused:

private float rayBlockCheckDistance = 10;
private void gridSnap()
{
    RaycastHit[] hits;
    hits = Physics.RaycastAll(transform.position, Vector3.forward, rayBlockCheckDistance);     

    GameObject gFloor = hits[0].transform.gameObject;
    //Transform tFloor = gFloor.transform;  //This Errors
    //Vector3 position = new Vector3(tFloor.position); //So this Errors aswell

    Destroy(gFloor); //But I can destroy the specific Block fine.
}

No errors are given for why I can’t apply transform as thus get the position of the first object in the raycast array, the Editor just flashes “Compiler errors”, but no errors are given in console or VS.

Both objects have box colliders/rigid bodies.

Looks like you are trying to set tFloor equal to an undeclared DirectFloor variable, Unless this is being initialized somewhere else. From looking at your code, I would first try changing that line to

Transform tFloor = gFloor.transform;

Then on the line below, change it to…

Vector3 position = tFloor.position;

The position variable of the transform is already a Vector3

One last thing, in your Destroy line, you can use Destroy(gFloor); since gFloor is already set to hits[0].transform.gameObject.

Hope this helps,
-Larry