Search Unity

Colored Triggers?

Discussion in 'Scripting' started by herold101, Feb 20, 2017.

  1. herold101

    herold101

    Joined:
    Jan 20, 2014
    Posts:
    22
    Hey all, I have been working on a small project lately where I want to make the 'player' to be able to move past walls with their own set of colliders, the player has 4 colors which it can switch up and the walls come in 4 identical colors.

    Getting to the point I dont know where and how to start scripting that when the player color is red it can pass through red walls but not green and so on with the rest of the 4 colors which would lets say be (Green, Yellow, Red, Blue)

    I mainly focus and study C# just to add as a side note.

    Any help is much appreciated, and thank you!
    Please note not looking for someone to make the entire script with me doing no work, I just simply require a start off so I know and I can see how the basics of it should be coded.
     
    Last edited: Feb 20, 2017
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    One option is when your player switches colors, you turn off the matching wall colliders so the player can just pass through.

    Another option may be adding trigger colliders to your wall colliders and if a player enters the trigger, checks to see if the color they have matches the wall, and then disables the blocking collider and turns it back on when the player leaves.

    Another option may be to setup collision layers. You could have it so the "red layer" doesn't collide with red, thus changing your players layer to match the proper color should allow them to past through doors on the same colored layer.

    I'm sure there are other options. Just some ideas.