How to set a public variable to a gameObject in the inspector through coding

When I select a unit in my game I want it so that when I select a unit, the public variable Selected_Unit will be set to the gameObject that I have selected. I have already made a raycast that works but I just don’t know how to set a public variable to a gameObject in the inspector by coding.

All you need to do is have a variable called selectedObject and assign it in the raycast with

		selectedObject = hit.transform.gameobject;