But if you want a foreign object to observe others than you can continue using your original raycast script and check if they have a specific tag on them, this is one example you can use:
In your code you use if (hit.collider != null ) so, you’d just replace with a specific test. You can even check for specific instances of an object, and not tag exactly.
I tried pointerdownhandler and pointerclickhandler and untiy will intercept my events but my function wouldn’t fire, I now have a new object detecting collision with the original object I want to touch.
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "bird")
{
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
{
RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint((Input.GetTouch(0).position)), Vector2.zero);
if (hit.collider != null)
{
GetComponent<BirdBounce>().Jumpies();
}
}
}
}
This is my code now and im getting a null reference exception. No idea what to do. I even tried event triggers.