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.");
}
}
}
8 Replies
Angius
Angius4mo ago
1. Define "doesn't work" 2. You'll probably get better help in the $unity server
DiamondPeople
DiamondPeople4mo ago
yeah i tried that and no one helped and what i mean by doesnt work is that i add the script to the object and what i think its supposed to do is apply it to the object as a material or shader or something but it doesnt
TheRanger
TheRanger4mo ago
What does the Log Warning say? Did it Log any of these Warnings?
DiamondPeople
DiamondPeople4mo ago
no
TheRanger
TheRanger4mo ago
which means that the method was never called for some reason Did you attach the script to an object?
DiamondPeople
DiamondPeople4mo ago
yes
TheRanger
TheRanger4mo ago
Can you show a screenshot of your object in the scene?
Want results from more Discord servers?
Add your server
More Posts