Hello, I am following a tutorial on how to make a character creation menu. I made a simple script that should allow me to press a left or right button to scroll through some character textures but I’m getting this error:
NullReferenceException: Object reference not set to an instance of an object.
I understand the gist of the problem and I think I know where the error is but I cannot find how to solve it.
Here’s my code:
using System.Collections;
using UnityEngine;
using System.Linq;
public class CharaCreation : MonoBehaviour {
[SerializeField] private Renderer rend;
private int breedID;
[SerializeField] private Texture[ ] breeds;
public void SelectBreeds(bool isForward) {
if (isForward) {
if (breedID == breeds.Length - 1) {
breedID = 0;
} else {
breedID++;
}
} else {
if (breedID == 0) {
breedID = breeds.Length - 1;
} else {
breedID–;
}
}
SetItem(“breed”);
}
private void SetItem(string type) {
switch (type){
case “breed”:
rend.materials[0].SetTexture(“_PrimaryTexture”, breeds[breedID]); //I think this line is the problem
break;
}
}
}
In the tutorial ‘_PrimaryTexture’ was the name where his custom shader had the texture he wanted to change. In my case I’m using a free asset and am unsure what I should be using in its place or if the shader he is using is required to make this bit of code function. Below I circled where I found my shader information with the texture I want to change. I’m not sure how to proceed.