Hello everyone! I am new to Unity, taking a class in it this semester. We are currently remaking Q*bert in 3D, it’s pretty fun but I’ve been having a problem with the biggest part of the game. The cubes changing colors when the Player hits it.
I attached the script to the Player(it’s a sphere) and the collision works but it changes the color of the sphere not the cube. I’ve tried putting the script on a prefab called Pyramid, it contains all my cubes, switching the appropriate names in the code. That doesn’t work either. I tried it on one of the individual cubes and that didn’t work either.
“Doesn’t work” is a difficult issue for us to help debug. You mentioned that when you have this script attached to the player, it changes the player object’s color. That doesn’t sound right with what I’m seeing in your screenshot, but just to be sure, are you positive you have the GameObjects tagged properly?
What a fun project! Q-Bert was one of my favorite games back in the day.
I agree with @Schneider21 , the script you posted ought to work. When faced with a mystery like this, you want to gather all the clues you can — and in particular, try to think of what assumptions you’re making, that you’re not really testing. The best/easiest way to do that is to dump more details into your print statement. Instead of just “it worked”, do something like:
print(gameObject.name + " collided with " + other.gameObject.name + ", so changing its material to " + colorOne);
Other assumptions to check:
Is your script really on the object you think it is — and only that object?
Do all your objects have the right Tags set on them?
Do all of your cubes have a unique material, or are they sharing materials? (Actually shouldn’t matter, since you’re accessing .material instead of .sharedMaterial, but still.)
Other things I’m not thinking of?
Finally, you asked a good question, but instead of posting a screen shot of code, paste the actual code into your post using the “Insert Code” button in the editing toolbar, right between the movie filmstrip and the floppy disk icon:
I’ll try all of those thank you so much! I need to really pick apart more. I will try to go more in depth. School is starting up again so I’m hoping I can get help from a teacher or fellow student. Thank you!