Help with casting a raycast C#

Hello,

I have a game where a block moves and the player has to navigate it through gates. The script I’m using uses transforn.translate to move the cube forward and sideways. But now it has no colliders because that method ignores them. The solution is to use a raycast. I have no idea how to do this though, I can’t get it to work. Can someone give the proper code? Thanks you.

my code:

using System.Collections;

public class testMotor
: MonoBehaviour {
 
public float MoveSpeed = 40;
public float SideSpeed = 10;

 
void Update () 
{

    float MoveForward = MoveSpeed * Time.deltaTime;
    float MoveSide = Input.GetAxis("Horizontal") * SideSpeed * Time.deltaTime; 
 
	
		
    transform.Translate(Vector3.forward * MoveForward);
    transform.Translate(Vector3.right * MoveSide);
 
	
        
		
}
}

C#

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    void Update() {
        Vector3 fwd = transform.TransformDirection(Vector3.forward);
        if (Physics.Raycast(transform.position, fwd, 10))
            print("There is something in front of the object!");
        
    }
}

Distance based

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    void Update() {
        RaycastHit hitForward;
        RaycastHit hitBack;
        RaycastHit hitLeft;
        RaycastHit hitRight;

        // forward
        if (Physics.Raycast(transform.position, Vector3.forward, out hitForward)) {
            float distanceForward = hitForward.distance;
        }

        // back
        if (Physics.Raycast(transform.position, -Vector3.forward, out hitBack)) {
            float distanceReverse = hitBack.distance;
        }

        // left
        if (Physics.Raycast(transform.position, Vector3.left, out hitLeft)) {
            float distanceLeft = hitLeft.distance;
        }

        // right
        if (Physics.Raycast(transform.position, Vector3.right, out hitRight)) {
            float distanceRight = hitRight.distance;
        }
        
    }
}