Color triggered collider?
Hi!
I'm making a 2D maze where there are blue and red pads that makes the player change its color. If the player steps on a blue pad, he'll turn blue and will be able to go through a blue wall. If the player steps on a red pad, he'll turn red and will be able to go through a red wall. A red player should not be able to pass a blue wall, and a blue player should not be able to pass a red door.
Right now, my player can go through any wall if he touches a pad. However, I want the wall (its box collider) to be color triggered, not triggered by the pad. I have no idea how to solve this. Can you guys help me?
This is what I've got so far:
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.CompareTag ("RedPad"))
{
transform.GetComponent<SpriteRenderer>().material.color= redcolor;
if (col.gameObject.CompareTag ("Player"))
{
GameObject.FindGameObjectWithTag("BlueWall").GetComponent<BoxCollider2D>().isTrigger = false;
}
}
if (col.gameObject.CompareTag ("BluePad"))
{
transform.GetComponent<SpriteRenderer>().material.color= bluecolor;
if (col.gameObject.CompareTag ("Player"))
{
GameObject.FindGameObjectWithTag("RedWall").GetComponent<BoxCollider2D>().isTrigger = false;
}
}
}
Your answer
Follow this Question
Related Questions
How to identify which collider generated OnTriggerEnter2D 0 Answers
Help with Trigger Colliders.. 0 Answers
Different colliders in prefabs 0 Answers
2D platformer Hide Action not working 0 Answers
Spawning with trigger 2 Answers