Collider2D.IsTouching (Collider2D other) Error

        //Death
        if (Collider2D.IsTouching(Collider2D other) {
            if (other.gameObject.tag == "Death") {
                transform.position = new Vector2 (-6,0);
                LivesLeft --;
            }
        }

This is not liking the “other” in both if statements (the first “other” is underlined in red, the second’s text color is red). What am I doing wrong?

This is not the same as function. In Function collider other, colliding objects send info about objects while in this if statment you just test variables. You could store thoese variables in colliding function

You have two options:
First:

public Collider2D death; //assign GameObject with "Death" tag

...
if (Collider2D.IsTouching(death) {
   //Do something
}

Second:

void OnCollisionEnters2D (Collider2D other) {
   if (other.gameObject.tag == "Death") {
      //Do something
   }
}
1 Like

I used the first example and I am now getting an error.

I have the reference as this:

public Collider2D Death;

    void Start() {

        Death = GameObject.Find ("Death").GetComponent<Collider2D> ();
    }

Is my reference wrong?

Well you refferencing is right, maybe it is wrong in part isTouching, or maybe at start of this object, object death is not predent, also i think it is faster and better to find with tag

The problem is that you’re trying to call the IsTouching function on the class and not on an object of that class. If a collision happens, you need to check if the colliding object is the “death” object, right? That means if the colliding object is called “other”, then you need to do “other == Death” or “GetComponent().IsTouching(Death)” or something.