Help: the name other does not exist in the current context

in the delivery script it says the name other does not exist in the current context
im using vs code
btw here is the script:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Delivery : MonoBehaviour

{

void OnCollisionEnter2D(Collision2D other)

{

    Debug.Log("i bumped ouch!");

}

 void OnTriggerEnter2D(Collider2D collision)

{
      // it says the name other does not exist in the current context  pls help
     if (other.tag == "Package") 

    {

     Debug.Log ("Package Picked Up");

    }

   

}

}

Look at what’s in the brackets to the right of your methods
OnCollisionEnter2D has a Collision2D named other
That means within the scope ( the {} braces ) of OnCollisionEnter2D you can use that other parameter that’s being passed in, but you will not be able to use it anywhere outside the scope of that method.

OnTriggerEnter2D doesn’t have an other parameter, it has a Collider2D named collision, but you are trying to call other within its scope but other does not exist as far as that method is concerned. It only knows of collision

That said OnTriggerEnter2D(Collider2D collision) shouldn’t even be valid unity code as far as I can tell from documentation and writing it out in a quick script, it should have Collider2D other in the brackets. Maybe you autocompleted the method with some archaic overload by accident.
It should read OnTriggerEnter2D(Collider2D other)

it worked OMG thx so much im such a noob praticali is like you said + another thing i didn’t pay attention lol btw thx

1 Like

It happens to the best of us, good luck with your future endeavors!

Also it’s best to mark the post that solved your problem as “Solution”, because it lets other know that’s what helped you in case other get the same issue.There should be a clickable button below each post to mark as solved

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms