Hi, I'm trying understand how this function works, my issue is: I need to call this function on another class that is declared. Example: Code (CSharp): public class PlayerController : MonoBehaviour { public bool test=true; void Update() { if(test) Itemtrigger.OnTriggerEnter2D(); } } ... and "OnTriggerEnter2D" is declared in another class, like : Code (CSharp): public class Itemtrigger : MonoBehaviour { public static void OnTriggerEnter2D (Collider2D other) { } } When I tried to compile this, MonoDevelop gave me a error ("There is no argument given that corresponds to the required formal parameter 'other' of 'Itemtrigger.OnTriggerEnter2D(Collider2D)"). What is the right arguments to call this ?
Hi. I thinkk That i can help you. Under text you have a code. Checking "your tag" is optional, but if you delete this every tirigger Will be return 'obj enter in trigger' Code (CSharp): void OnTriggerEnter2D(Collider2D col) { if(col.collider.tag=="yourtag") { test=true;} } void Update() { if(test) print("obj enter in tirigger); }
OnTriggerEnter2D is a function that is called every time a collider enters on a gameobject's 2D collider marked as trigger. The propper way to use OnTriggerEnter2D is: Code (CSharp): public class ExampleClass : MonoBehaviour{ void OnTriggerEnter2D(Collider2D other) { Debug.Log("hi"); } } in a gameobject which has attached a 2D collider marked as trigger. And by the way, you should remove the static keyword, cause it makes no sense (it would be as a "shared method" for all Itemtrigger instances, so everytime a collider enters on a certain object, the rest Itemtrigger's objects would execute OnTriggerEnter2D(), even if there aren't any colliders entering on its colliders. Obviously is not a desirable behaviour)