© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
11 replies
DiamondPeople

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.");
        }
    }
}
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.");
        }
    }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ What is wrong with this code???
C#CC# / help
17mo ago
what is wrong with this code?
C#CC# / help
4y ago
what is wrong with this?
C#CC# / help
4w ago