chnselim
chnselim

Reputation: 254

unity2D gameObject tag does not work

I'm new on Unity2D.Although I set my ground tag to 'GROUND', if condition does not work..

void onCollisionEnter2D(Collision2D other){
    if (other.gameObject.tag == "GROUND"){
        isGrounded = true;
        Jumping = false;
        anim.SetInteger("Status", 0);
    }
}

Upvotes: 0

Views: 1489

Answers (2)

IRAndreas
IRAndreas

Reputation: 441

Try using CompareTag() to check the tag of the gameObject.

void onCollisionEnter2D(Collision2D other){
    if (other.gameObject.CompareTag("GROUND")){
        isGrounded = true;
        Jumping = false;
        anim.SetInteger("Status", 0);
    }
}

Upvotes: 1

Programmer
Programmer

Reputation: 125245

The function is not even being called. It is OnCollisionEnter2D not onCollisionEnter2D. Fix that and your problem should be solved.

Not related to your problem, but it is more efficient to use the CompareTag function to compare tags. So your if (other.gameObject.tag == "GROUND") should be if (other.gameObject.CompareTag("GROUND"))

Upvotes: 3

Related Questions