How to assign layer via script unity

I am using procedural gen to generate chunks, there is no chunk prefab, I am watching a tutorial by b3agz how to code a game like Minecraft, I want to make a custom character pls help.

You can simply use gameObject.layer = layer;.

This example is from the Unity API:

// Put the game object in the ignore raycast layer (2)

using UnityEngine;

public class ExampleClass : MonoBehaviour
    void Awake()
        //gameObject.layer uses only integers, but we can turn a layer name into a layer integer using LayerMask.NameToLayer()
        int LayerIgnoreRaycast = LayerMask.NameToLayer("Ignore Raycast");
        gameObject.layer = LayerIgnoreRaycast;
        Debug.Log("Current layer: " + gameObject.layer);