Ignore collision in particular situation

My game contain two states for particular character.
If my character in state 1 then I want collision need to be happen but in state 2 of same character I don’t want any collision need to be happen.

So how to manage this type of situation through coding?
I didn’t have any idea at present.

Maybe have some variables for your different states.
var State1
var State2

Then add a code for your different states.
Then, use these if statements:
function Update(){
if(State2 == true){
collider.isTrigger = true;

//hope this helps. i'm not a pro at coding ;)

Hi Siddharth,
you can do one thing for that in second stage find the collider in run time and check property Is Tirigger true then after OnCollisionEnter will not work with that coolider.

I have created multiple layer. One which detect collision and other one not.

Using collision matrix, Edit->Project Setting->Physics2D in this I handled collision manually and specify layer collision carefully.

So when I want collision don’t happen at that time I changed layer of particular game object.

If you want any more detail about this then I will provide it. If this solution work for you also.