So I have a prefab wall “strip” with a grid on it, and want to select cells on it that will highlight, to be used for a variety of possible things (doors, notes, numbers, etc). The values are stored in an array. I have the hit.texcoord.x working great for the one wall—the array updates, I can test the cells, everything is fine. There’s a script attached to the prefab which manages all this, including creating a Texture2D to watch for the mouseclick hits. (There are three other materials in the prefab which manage the grid, highlighting, and “playback” graphics.)
Then I added three more walls (duplicated the first one), and although they all “work” the same way, if you click on any of them, the other walls act as though you clicked all of them at that same cell…their arrays get updated all at once. Can’t figure it out…my thought is that the four prefabs are somehow sharing the texture? So that the hit.texcoords.x happens on any of them, they all “think” they’ve been clicked? Everything else about each prefab seems independent—I can randomly populate the array in each through the script, and they all come up different. But clicking on the texture propagates to all of them, for some reason, regardless of where they are on the screen.
It’s weird and might be tricky to show in code, so hopefully someone can understand what I’m saying and point me in the right direction. Or if there’s another way to test where something hits an object without using a texcoord, that would be fine, but this was the best way I found so far (it reports relative positions, which I need).
I know I could do a workaround with non-prefabs, each with their own texture (maybe?), or possibly there’s another way. But I’d like to be able to instantiate these prefabs wherever and have them work independently. (At the moment I’m not instantiating them, they were added to the scene manually, just for testing.)
Guess I’m just a bit lost as to how textures are managed among prefab instances…any way to create them on a per-instance basis, so that raycasting and hit.texcoord functions stay local to that one only?
Thanks!