Пример #1
0
    private void HandleTap(GameObject tappedObject)
    {
        ITouchable touched = tappedObject.GetComponent<ITouchable>();

        if (touched != null)
        {
            touched.OnTouch();
        }
    }
Пример #2
0
    void OnTriggerEnter(Collider other)
    {
        ITouchable collectable = other.gameObject.GetComponent <ITouchable>();

        if (collectable != null)
        {
            collectable.OnTouch();
        }
    }
Пример #3
0
    //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();
        }
    }