Animate only touched object

Yes, I know it’s a total noob topic, but a swear I have been all over the scripting docs and the forums but I still cannot find an answer.

If I have multiples of the same object, how can I animate only the one I touch? Every script I have tried animates every object of the same type. I have tried Collider.tansform, Collider.gameObject, Collider.GetInstanceID(). Nothing works. Every instance of the character animates when I touch one of them. Here is the most recent code I have been using:

var hit : RaycastHit;
function Update () {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Input.GetMouseButtonDown (0)) //Returns true during the frame the user touches the object
{
if (Physics.Raycast (ray, hit, 200))
{
var me:Collider=hit.collider;
me.transform.gameObject.animation.CrossFade(“Walk1”);
}
}

}

Also, note I have had to rely on the mouse code since Raycast needs a Vector3 and iPhone.touch sends out a Vector2. How can I convert this?

Sorry for the “noobism” but I honestly cannot figure this out. Basically, I cannot get the ultimate parent object of a Collider since there is no Collider.parent command.

P.S.: I have also tried things like this:

transform.gameObject.transform.animation.CrossFade(“Walk1”);

When I just access the transform for translation or rotation it works, like so…

transform.Rotate(0,10,0);

This will only rotate the object I touch, but when I try animation commads, every instance of the character animates. Someone out there must have done something similar to this already so I’m surprised I haven’t found anything similar yet.

I have also tried “transform.parent” and that did not work either. All the characters animate when I click on one of them. Please, does anyone know how to accomplish this?

OK. This code seems to be working. I now have to see if it will work in the actual game.

var hit : RaycastHit;
function Update () {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Input.GetMouseButtonDown (0)) //Returns true during the frame the user touches the object
{
if (Physics.Raycast (ray, hit, 200))
{
var me:Collider=hit.collider;
me.transform.parent.animation.CrossFade(“Walk1”);
}
}

}

P.S.: Why didn’t anyone respond?

Bugzilla wrote:

OK. This code seems to be working. I now have to see if it will work in the actual game.
var hit : RaycastHit;
function Update () {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Input.GetMouseButtonDown (0)) //Returns true during the frame the user touches the object
{
if (Physics.Raycast (ray, hit, 200))
{
var me:Collider=hit.collider;
me.transform.parent.animation.CrossFade(“Walk1”);
}
}
}

Just wondering if you got all this to work. I’m having the same issue.
As a test, I have two animations linked to two different buttons.

Touch either button and they both play.

Like you I’ve had difficulty getting a solid response from the forum.
So the key is the collider?

I was looking into LayerMask. I posted a couple questions in the forum but no good response came.

Thanks in advance for any insight you can send my way.

Signed:
Even more of a noob that you

not sure if that it’S adequat for your need but for a shooter game also using many prefab character which I shoot at I also get that issue of having them all animating shooting only one, so i just put them in an array at begining and use an unique index for each prefab , corresponding to their order on the array, not pretty solution i assume but at least it work for my needs.

I haven’t learned how to use arrays yet and I keep reading that they’re very useful and powerful.

I’ll do a search on arrays and buttons and see what I find.

If there’s anything that you know of that will help me as far as arrays are concerned I’d love to take a look.

Thanks a lot!