Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        ObjectGoal = A1.Goal();
        if (Input.touchCount > 0 && !locked)
        {
            Touch   touch         = Input.GetTouch(0);
            Vector2 touchPosition = Camera.main.ScreenToWorldPoint(touch.position);

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

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

            case TouchPhase.Ended:
                if (Mathf.Abs(transform.position.x - ObjectGoal.x) <= 0.5f && Mathf.Abs(transform.position.y - ObjectGoal.y) <= 0.5f)
                {
                    transform.position = new Vector2(ObjectGoal.x, ObjectGoal.y);
                    locked             = true;
                }
                else
                {
                    transform.position = position_initial;
                }
                break;
            }
        }
    }
Ejemplo n.º 2
0
 void Start()
 {
     A1               = GameObject.FindObjectOfType <ControlGame>();
     ObjectGoal       = A1.Goal();
     position_initial = transform.position;
 }