ACIDMUD
ACIDMUD

Reputation: 1

How to detect collision only of equal colors?

I have a parent element ("MainSquare") and 4 child elements ("redCube, blueCube, yellowCube and greenCube").

I need to detect a collision between the falling "Enemy Square" and the child elements.

enter image description here

Upvotes: 0

Views: 52

Answers (1)

Arslan Ali
Arslan Ali

Reputation: 460

  1. Attach Rigid-body to falling enemy object.Clear Your rigid-body Gravity checked. Set Random X-axis for enemy falling position and disable constraint for other enable for Y-Axis.
  2. Attach Box-Collider to enemy object and to the main 4 square separately or over the parent but for color matching process you must have to attach 4 box colliders to 4 boxes as well as adjust them scaling and position in component tab of box collider in inspector.

Do Code like that similar to your approaches...

    void OnCollisionEnter(Collision col)
    {
    if(col.gameObject.name.equals("redCube"))
    {
    ............
    ..........
    }
    else if(col.gameObject.name.equals("blueCube"))
    {
    .........
    ........
    }
    ................
    ................
    }

But in your sense,you also have to set space or any button down for rotating your parent-cube in Y Rotation for Get Detection similar to enemy. As I understand Problem as such I replied sorry for any poor description because I'm new here too.

Upvotes: 2

Related Questions