Hey guys, new to BGE and I’m a little curious as to how clicking objects work.
The scene is as follows; I have a cube, when I left click it turns red, when I left click again, it turns back to the original colour (grey). But I have two separate meshes, a grey cube and a red cube. I only want to change to the material, but I have no idea how. Any ideas?
You could use an action to animate the material’s color, or you could check the Object Color box in the materials tab and then just just set the color using the KX_GameObject.color property.
Actually I just made a test blend, and it seems like you only need to have object color checked if you’re using GLSL. Here’s the file. Just hit space to turn the Cube red. The code is literally 4 lines.
As far as I know, it’s not possible to change objects’ materials in the game engine. You’ll have to use one of the two methods I suggested or just replace the mesh like you’re already doing.