示例#1
0
    public void OnDrag(PointerEventData eventData)
    {
//		throw new System.NotImplementedException ();
        //центр родителя относительно контейнера
        Vector2 parentCenter = new Vector2(
            parentTransform.anchorMax.x * canvasTransform.rect.width + parentTransform.anchoredPosition.x,
            parentTransform.anchorMax.y * canvasTransform.rect.height + parentTransform.anchoredPosition.y
            );
//		print (Screen.width + "\t" + cs.referenceResolution.x);


        float mx = Input.mousePosition.x / (float)Screen.width;
        float my = Input.mousePosition.y / (float)Screen.height;

        Vector2 pos = new Vector2(
            mx * canvasTransform.rect.width - parentCenter.x,
            my * canvasTransform.rect.height - parentCenter.y
            );

        float dist = Vector2.Distance(Vector2.zero, pos);

        if (dist > maxDistance)
        {
            pos = Vector2.ClampMagnitude(pos, maxDistance);
        }
        transform.localPosition = pos;



        spaceship.Acceleration(pos.x / maxDistance, pos.y / maxDistance);
    }