- Home /
Button to change layers
I'm making a plattform game, and for the collisions, i group up all the objects that are part of the plattforms and set them in a same layer
public LayerMask collisionMask;
so the player collides with every object in that layer.
i was thinking in setting a button to change that layer so the player can get through the plattforms and collides with others plattforms set in another layer, is there any way that i can do this?
Answer by smallbit · Jul 18, 2014 at 06:40 AM
Just set each group of platforms (colliders) to separated layer (in the inspector) and than in the button use
Physics2D.IgnoreLayerCollision(1, 2, true); //disable collision detection
or
Physics2D.IgnoreLayerCollision(1, 2, false); //enable collision detection
where "1" will be the layer of your player collider and "2" or any other number will be the layer of the group. You can enable or disable collision with multiple layers at the same time. The numbers you get from layer editor. Read more here http://docs.unity3d.com/ScriptReference/Physics2D.IgnoreLayerCollision.html
Your answer
Follow this Question
Related Questions
Multiple collisions not working.Plz help 0 Answers
OnTriggerEnter() not called 1 Answer
C# Plane Collision Detection 1 Answer
Check if colliding with a layer 2 Answers
C# GameObject is not detecting collision with Character Controller 2 Answers