Example #1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        //  use else if to reduse computation power . also this method is not optimal , there is a better ans shoter way of doing things , but let's just keep it simple


        if ((collision.gameObject.tag == "liver" && gameObject.tag == "liver") || (collision.gameObject.tag == "kidney" && gameObject.tag == "kidney") || (collision.gameObject.tag == "skin" && gameObject.tag == "skin"))
        {
            //  Debug.Log("Hello");
            score.points += 1;
            Destroy(gameObject);
            Destroy(collision.gameObject);
            score.updateSceneIfNeeded();
        }

        if (collision.gameObject.tag == "bone" && gameObject.tag == "bone" || (collision.gameObject.tag == "cornea" && gameObject.tag == "cornea") || (collision.gameObject.tag == "pancreas" && gameObject.tag == "pancreas"))
        {
            //  Debug.Log("Hello");
            score.points += 1;
            Destroy(gameObject);
            Destroy(collision.gameObject);
            score.updateSceneIfNeeded();
        }
    }
Example #2
0
    private void Update()
    {
        if (Input.touchCount > 0 && !locked)
        {
            Touch   touch    = Input.GetTouch(0);
            Vector2 touchPos = Camera.main.ScreenToWorldPoint(touch.position);

            switch (touch.phase)
            {
            case TouchPhase.Began:
                if (GetComponent <Collider2D>() == Physics2D.OverlapPoint(touchPos))
                {
                    deltaX = touchPos.x - transform.position.x;
                    deltaY = touchPos.y - transform.position.y;
                }
                break;

            case TouchPhase.Moved:
                if (GetComponent <Collider2D>() == Physics2D.OverlapPoint(touchPos))
                {
                    transform.position = new Vector2(touchPos.x - deltaX, touchPos.y - deltaY);
                }
                break;

            case TouchPhase.Ended:
                if (Mathf.Abs(transform.position.x - boneplace.position.x) <= 0.5f &&
                    Mathf.Abs(transform.position.y - boneplace.position.y) <= 0.5f)
                {
                    transform.position = new Vector2(boneplace.position.x, boneplace.position.y);
                    score.points      += 1;
                    locked             = true;
                    score.updateSceneIfNeeded();
                }
                else
                {
                    transform.position = new Vector2(initialPosition.x, initialPosition.y);
                }
                break;
            }
        }
    }