private void HandleTap(GameObject tappedObject) { ITouchable touched = tappedObject.GetComponent<ITouchable>(); if (touched != null) { touched.OnTouch(); } }
void OnTriggerEnter(Collider other) { ITouchable collectable = other.gameObject.GetComponent <ITouchable>(); if (collectable != null) { collectable.OnTouch(); } }
//para verificar se o toque foi em algum gameObject com ITouchable private void Check(Vector2 touchPosition) { RaycastHit2D hitInformation = Physics2D.Raycast(touchPosition, Camera.main.transform.forward, 0); Collider2D collide = hitInformation.collider; if (collide == null) { return; } ITouchable touchable = collide.gameObject.GetComponent <ITouchable>(); if (touchable != null) { touchable.OnTouch(); } }