I’m trying to achieve a “Smart Block” feature on my game, since it has some kind of level editor in it.
But what is a “Smart Block”?
A Smart Block would be a Quad that knows if there are any other quads touching it and on what side they are. And, based on this, it determines where it is and what it is (a corner, a side, surrounded/fill) and then it changes the material and rotations based on those informations.
And… Smart Block is the name I gave to this kind of function.
The Issue
But, and there’s alway a but on these posts, for some reason it is not working. It detects the positioning allright, but never changes the material. Could anyone help me?
hitChecker is an array. An array is a reference type. When you compare an array to another array with == you only compare their reference not the content of the array.
int[] arr1 = new int[]{1, 2, 3};
int[] arr2 = new int[]{1, 2, 3};
if (arr1 == arr2) // this can never be true as arr1 and arr2 hold two completely seperate array instances.
If you want to compare the content of the two arrays you have to use a loop and do an element by element comparison.
The issue was at line 48 (when I compare the two arrays). I solved it by comparing manually if the values were equal. Why I can’t compare arrays with == or .Equals() I’ll never know. (Maybe I find out some day).
private Material thisMaterial; this variable is not set or used within the script. not sure if that is intentional.
besides that, the code: GetComponent<Renderer>().material = blockType[j].material; will set the script’s gameobject to the material set inside of the BlockType class. Is there a material set inside of the BlockType object being accessed from the array? I’d do a null check before setting it.
you’d also have to compare the value inside of both arrays hits and hitChecker to each other and not the array themselves…