Search Unity

[SOLVED] Why are my points not moved?

Discussion in 'Scripting' started by Deleted User, Aug 21, 2014.

  1. Deleted User

    Deleted User

    Guest

    the debug message on line 71 shows what the NEW x value for my point should be but in reality, the point is not moved.

    Code (CSharp):
    1.         void Update ()
    2.         {
    3.                 if (Input.touchCount > 0) {
    4.                         for (int i = 0; i < Input.touchCount; i++) {
    5.                                 Touch touch = Input.GetTouch (i);
    6.                                 touchDuration [touch.fingerId] += Time.deltaTime;
    7.                                 Debug.Log ("Finger " + touch.fingerId + " - Time Touched: " + touchDuration [touch.fingerId]);
    8.                    
    9.                                 if (touch.phase == TouchPhase.Began) {
    10.                                         touchPoints [touch.fingerId] .Add (touch.position);
    11.                                         Debug.Log ("Finger " + touch.fingerId + " - Start Point: " + touch.position);
    12.                                 }
    13.                    
    14.                                 if (touch.phase == TouchPhase.Moved) {
    15.                                         touchPoints [touch.fingerId].Add (touch.position);
    16.                                         Debug.Log ("Finger " + touch.fingerId + " - Moved to Point: " + touch.position);
    17.                                 }
    18.                    
    19.                                 if (touch.phase == TouchPhase.Ended) {
    20.                                         touchPoints [touch.fingerId].Add (touch.position);
    21.                                         Debug.Log ("Finger " + touch.fingerId + " - End Point: " + touch.position);
    22.                                         Debug.Log ("Finger " + touch.fingerId + " - # of Points Saved: " + touchPoints [touch.fingerId].Count);
    23.                                         for (int j = 0; j < touchPoints[touch.fingerId].Count; j++) {
    24.                                                 Transform t = Instantiate (touchPoint, Camera.main.ScreenToWorldPoint (touchPoints [touch.fingerId] [j]), Quaternion.identity) as Transform;
    25.                                                 t.Translate (t.position.x, t.position.y, 0);
    26.                                                 Debug.Log ("Finger " + touch.fingerId + " - ScreenToWorldPoint: " + touchPoints [touch.fingerId] [j]);
    27.  
    28.                                         }
    29.                                         Scale (touch.fingerId);
    30.                                         //    touchPoints = Spread (touchPoints, touch.fingerId);
    31.                                         touchPoints [touch.fingerId].Clear ();
    32.                                         touchDuration [touch.fingerId] = 0;
    33.                                 }
    34.                    
    35.                                 if (touch.phase == TouchPhase.Canceled) {
    36.                                         touchPoints [touch.fingerId].Clear ();
    37.                                         touchDuration [touch.fingerId] = 0;
    38.                                         Debug.Log ("Finger " + touch.fingerId + " - Touch canceled.");
    39.                                 }
    40.                         }
    41.                 }
    42.         }
    43.  
    44.         private void Scale (int fingerId)
    45.         {
    46.                 //    List<Vector2> newPoints = new List<Vector2> ();
    47. //                for (int i = 0; i < touchPoints[].Count; i++) {
    48. //                        newPoints.Add (touchPoints[] [i]);
    49. //                }
    50.                 Debug.Log ("Finger " + fingerId + " - Points to scale:" + touchPoints [fingerId].Count);
    51.                 float minX = float.MaxValue, minY = float.MaxValue, maxX = float.MinValue, maxY = float.MinValue;
    52.                 for (int i = 0; i < touchPoints[fingerId].Count; i++) {
    53.                         if (touchPoints [fingerId] [i].x < minX) {
    54.                                 minX = touchPoints [fingerId] [i].x;
    55.                         }
    56.                         if (touchPoints [fingerId] [i].y < minY) {
    57.                                 minY = touchPoints [fingerId] [i].y;
    58.                         }
    59.                         if (touchPoints [fingerId] [i].x > maxX) {
    60.                                 maxX = touchPoints [fingerId] [i].x;
    61.                         }
    62.                         if (touchPoints [fingerId] [i].y > maxY) {
    63.                                 maxY = touchPoints [fingerId] [i].y;
    64.                         }
    65.                 }
    66.                 Debug.Log ("Finger " + fingerId + " - minX = " + minX + " - minY = " + minY + " maxX = " + maxX + " maxY = " + maxY);
    67.                 float scaleX = (maxX - minX) / RESCALE, scaleY = (maxY - minY) / RESCALE;
    68.                 Debug.Log ("Finger " + fingerId + " - scaleX = " + scaleX + " - scaleY = " + scaleY);
    69.                 for (int i = 0; i < touchPoints[fingerId].Count; i++) {
    70.                         touchPoints [fingerId] [i].Set ((touchPoints [fingerId] [i].x - minX) / scaleX, (touchPoints [fingerId] [i].y - minY) / scaleY);
    71.                         Debug.Log ((touchPoints [fingerId] [i].x - minX) / scaleX);
    72.                         Debug.Log ("Finger " + fingerId + " - newPoints[" + i + "]: " + touchPoints [fingerId] [i]);
    73.                         Transform t = Instantiate (scaledPoint, Camera.main.ScreenToWorldPoint (touchPoints [fingerId] [i]), Quaternion.identity) as Transform;
    74.                         t.Translate (t.position.x, t.position.y, 0);
    75.                         Debug.Log ("Finger " + fingerId + " - newPoints[" + i + "] ScreenToWorld: " + Camera.main.ScreenToWorldPoint (touchPoints [fingerId] [i]));
    76.                        
    77.                 }
    78.                 Rect r = new Rect (0, 0, (maxX - minX), (maxY - minY));
    79.                 Debug.Log ("Fingera " + fingerId + " - Points Scaled: " + touchPoints [fingerId].Count);
    80.  
    81.         }