не догоняю чого воно не працює, а саме координати камери відскакують назад на наступному ouchPhase.Moved Що я впустив?
public class MyCam : MonoBehaviour {
// Use this for initialization
private Vector2 last, old;
private Vector3 camPos;
private Camera cam;
private void DrawInfo()
{
int w = Screen.width, h = Screen.height;
GUIStyle style = new GUIStyle();
Rect rect = new Rect(0, 0, w, h * 2 / 100);
style.alignment = TextAnchor.UpperLeft;
style.fontSize = h * 2 / 100;
style.normal.textColor = new Color(0.0f, 0.0f, 0.5f, 1.0f);
string text;
text = string.Format("X:{0}", last.x);
text = text + string.Format(" Y:{0}\n", last.y);
text = text + string.Format(" Xold:{0}", old.x);
text = text + string.Format(" Yold:{0}\n", old.y);
text = text + string.Format(" CamX:{0}", camPos.x);
text = text + string.Format(" CamY:{0}", camPos.y);
text = text + string.Format(" CamZ:{0}", camPos.z);
GUI.Label(rect, text, style);
}
void Start ()
{
cam = GetComponent<Camera>();
}
// Update is called once per frame
void Update ()
{
if(Input.touchCount == 1)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Moved)
{
last = touch.position;
camPos = cam.transform.position;
Vector2 direction = (old - last);
float extraLen = cam.orthographicSize / cam.pixelHeight * 2f;
cam.transform.position += transform.TransformDirection( (Vector3) (direction * extraLen) );
old = last;
}
}
if (Input.touchCount == 2)
{
}
}
void OnGUI()
{
DrawInfo();
}
}