I am making a 2D game where players compete to colour platforms by walking on them (think move or die colouring surfaces). It has up to 4 players and each has an assigned colour; red, green, blue and yellow. I need to create a script for changing the colour of a block object to the colour assigned to the player that collides with it as it happens. This needs to be able to re-write what colour has been applied repeatedly. I used a tutorial from the unity youtube channel -
- for help with collisions but the collisions do not include changing objects and the player still passes through objects when it collides on the side. Any thoughts?
To give general direction, it would make sense to make a script for the blocks themselves that check for a player object in OnCollisionEnter2D(), then change to that player’s color if a player is found. Each player could have a color property that is set before the game starts based on player number, and the block will look up the player’s color after a collision with a player happens and change to that color. You’ll probably also want to update the score in the game controller object (subtract points from old color, add points to new color).
How do you want to handle two players standing on the same block? The way I see it, there are two easy options: The most recent player to touch the block gets the color, or the block will stay the color of the first player that touches it until that player leaves.