Moving two objects with this code

Hi, all,
I’m using the following code to move a 2D object.
It works well, but I would like to modify this script to enable two objects to be dragged independently.

Any ideas?

Thanks,

Greg

var object : GameObject; 
var speed = 5.0;
var swipeVector = Vector2.zero;

function Update () {
  if(iPhoneInput.touchCount > 1) {
    var touch = iPhoneInput.GetTouch(1);
    swipeVector = touch.positionDelta * Time.deltaTime * speed;
    object.transform.position += swipeVector;
  } 
transform.position.x = Mathf.Clamp(transform.position.x, -5, 5.2);
transform.position.y = Mathf.Clamp(transform.position.y, -1, 4.5); 
}

I’m still trying to solve this one. Any ideas?

Have you looked at the touchphases demo project on the unity site as that shows multiple objects tracked and moving which is pretty well what it sounds like you are after. (Its in the iphone resources section)

Once you have the “latching” down you can then just add your swipe vector code.

Thanks, Blastone! That helped a lot.

Best,

G

The following script is attached to a camera. I want to touch another object and move it, effectively overriding the below script.
Any suggestions?

Thanks,

Greg

var object : GameObject;
var speed = 5.0;
var swipeVector = Vector2.zero;

function Update () {
  if(iPhoneInput.touchCount > 1) {
    var touch = iPhoneInput.GetTouch(1);
    swipeVector = touch.positionDelta * Time.deltaTime * speed;
    object.transform.position += swipeVector;
  }
transform.position.x = Mathf.Clamp(transform.position.x, -5, 5.2);
transform.position.y = Mathf.Clamp(transform.position.y, -1, 4.5);
}

BTW, I am using the above script on my second object as well. Is there a way to Raycast to this second object and perhaps stop the script on my camera while it was touched?

I realized that what I am looking for is a way to disable a component with a Raycast.
Any ideas?

Are you saying you want to use a raycast from the camera to detect/move an object in the scene, but hold the camera still while you are doing that?

Hi, Andeeee
I am using the above touch-to-move script on both an object and my main camera. As a result, both the object and camera move in tandem. I want to attach a raycast and a line of code to the object that will temporarily disable this touch-to-move code on my camera. This would allow the user to move the object independently of the camera when the objects collider is hit by a raycast.

Any suggestions?