what is wrong with this code

ive been wondering if i can add a cubemap onto an object, so i asked my friend if there was a way and he sent me a script. only problem is that it doesnt work. is anyone able to help or see whats wrong?

using UnityEngine;

public class AddCubemap : MonoBehaviour
{
    public Cubemap cubemap;

    void Start()
    {
        if (cubemap != null)
        {
            Renderer rend = GetComponent<Renderer>();
            if (rend != null)
            {
                Material mat = rend.material;
                if (mat != null)
                {
                    mat.SetTexture("_Cube", cubemap);
                    mat.shader = Shader.Find("Skybox/Cubemap"); // Set the shader to use cubemap
                }
                else
                {
                    Debug.LogWarning("Material not found on this GameObject.");
                }
            }
            else
            {
                Debug.LogWarning("Renderer component not found on this GameObject.");
            }
        }
        else
        {
            Debug.LogWarning("Cubemap not assigned to the script.");
        }
    }
}
Was this page helpful?