OK, so I have this working fine, except it moves every piece it’s attached to all at once. It doesn’t matter where I tap, all six pieces move at once.
// Moves object according to finger movement on the screen
var speed:float = 1.0;
function Update () {
// moves unit across board when touch and dragged
if (iPhoneInput.touchCount > 0 iPhoneInput.GetTouch(0).phase == iPhoneTouchPhase.Moved) {
// Get movement of the finger since last frame
var touchDeltaPosition:Vector2 = iPhoneInput.GetTouch(0).deltaPosition;
// Move object this is attached to across XY plane
transform.Translate (-touchDeltaPosition.x * speed, -touchDeltaPosition.y * speed, 0);
}
}
I am trying to modify it so that each piece is is attached to is moved separately, but this isn’t working …
// Moves object according to finger movement on the screen
var speed:float = 1.0;
var thisItem : GameObject; // ADDED A VARIABLE TO IDENTIFY THIS PIECE
function Update () {
// moves unit across board when touch and dragged
if (iPhoneInput.touchCount > 0 iPhoneInput.GetTouch(0).phase == iPhoneTouchPhase.Moved) {
// Get movement of the finger since last frame
var touchDeltaPosition:Vector2 = iPhoneInput.GetTouch(0).deltaPosition;
// Move object this is attached to across XY plane
// ADDED thisItem VARIABLE HERE
thisItem.transform.Translate (-touchDeltaPosition.x * speed, -touchDeltaPosition.y * speed, 0);
}
}
How do I make each piece this is attached to move separately when they are touched and dragged?
Hi,
Basic question. Are they group with one being the parent and the other the Child Components?
If so, you are probably moving the Parent Component and it automatically moves the other ones since they are related.
Nope, they’re all separate objects (they need to be).
I do understand that the general statement … if (iPhoneInput.touchCount > 0 iPhoneInput.GetTouch(0).phase == iPhoneTouchPhase.Moved) … is the issue. It’s saying, hey, touch the screen and everything with this attached will move.
That’s why I added the variable to the script to identify a game object for each object this is attached to. Without success, though.
And the only way you could encounter, other than the Parent/Child relationship, problem, would be;
…I have no clue because I have a script that moves GameObjects with the mouse and it works fine.
In C#
IEnumerator OnMouseDown()
{
Vector3 screenSpace = camera.WorldToScreenPoint(transform.position);
Vector3 offset = transform.position - camera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z));
while (Input.GetMouseButton(0))
{
Vector3 curScreenSpace = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z);
Vector3 curPosition = camera.ScreenToWorldPoint(curScreenSpace) + offset;
transform.position = curPosition;
yield return null;
}
}
But I made sure that they don’t have the same name just to avoid confusion. Because when you have a script attached to many GameObjects, if they all have the same name, you may encounter problems such as the one you have there… well there’s a possibility 
Also, one more thing, this is a strech but have you tried replacing translate to position and see what it does?