How can you apply a Material to a GameObject in Unity?

There are several ways to apply a Material to a GameObject in Unity:

1. Drag and Drop: You can drag and drop a Material from the Project Window onto the GameObject in the Scene View or the Hierarchy Window.

2. Inspector: You can select the GameObject in the Scene View or the Hierarchy Window and in the Inspector Window, navigate to the Renderer component or Mesh Renderer component (depending on your GameObject), and then assign a Material to the Material slot.

3. Scripting: You can use scripting to apply a Material to a GameObject. Here's an example script:

```csharp
public class ApplyMaterial : MonoBehaviour
{
public Material material;

void Start()
{
GetComponent().material = material;
}
}
```
In this script, we assign a Material to the public variable 'material' and then in the Start() function we get the Renderer component of the GameObject and set its material to the assigned material.

4. Prefab: You can apply a Material to a Prefab and then instantiate the Prefab in your scene. The instantiated GameObject will have the Material applied to it.

Publication date: