I am making a simple 2D platformer runner game like Fun Run. I want the player to go through walls for a second when he respawns. To implement this feature, I added an extra layer (GhostPlayer) to the game. Player is normally in Player layer which collides with everything but in GhostPlayer Layer it only collides with the frame and not with the obstacles on the road.
Both layers are working as intended, if I change the layer and then play. However, if I change the layer in runtime using
gameObject.layer = LayerMask.NameToLayer("GhostPlayer");
player keeps colliding to the obstacles even though I can see in the inspector that I successfully changed the layer.
I do not want to disable the collider2D since then player falls down. And I will also use this method to implement a Dash skill to dash forward a distance where player will not collide with obstacles but will be able to get coins or buffs on the way. That said, any other way to implement this is welcome.
Thank you in advance!