iOS : Moving multiple clones individually

Hello Everyone,

I’m in the process of making a 2D iOS game and have run into some trouble. I’ve searched everywhere I can think of for an answer or advice to no avail.

In my game, a dynamic number of prefabs are instantiated throughout the scene, and I need to be able to touch one, and drag it along the x-axis. The problem is, if I use a raycast to find a gameobject using a tag, or a gameobject with a name, or if I declare a gameobject as a variable, or use a transform it will move all of the clones at once, all the clones will fly to my finger and group together. I need to be able to touch any clone and move it by itself, then move on and touch another and move that by itself.

Any help or advice would be greatly appreciated, I’ve thrown out all my scripts and I’m all out of ideas on how to make this work. Thanks in advance.

If this is for iOS then finding gameobjects based on name can eat up some resources depending on how many prefabs you are proliferating your scene with. Why not cache your objects on Start() in an array then reference that … raycast for tag then see which object it is in the array then just do all of your movement on that array element?

Or am I barking up the wrong tree?

*Edit: also by using “this” as in “this.transform.position +=” any movement or action resulting from this script on your prefab will only affect the individual gameobjects.

Thank you, Ill try that. I never thought to use “this” either.