Problem with raycast

Hi,

For my Android game I have animated a character with mecanim. When I touch this character, it starts walking (see script).

function Update ()
{
       for (var touch: Touch in Input.touches)
       {
           if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
        {
            var ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
            var hit: RaycastHit;
   
            if(Physics.Raycast(ray, hit))
            {
                // start walking
            }
        }
    }
}

Now I have a second character. It’s a duplicate of the first one but all the names, animator controller, etc are changed. But when I hit one of the characters, both characters are walking. What I would like to have is that only the character that you hit is gonna walk.
I think I have overlooked something. Why is there a connection between the two different raycasts?

Since they both check against a single touch - any single touch anywhere - they will both do whatever you tell them to do. If the walking is just happening whenever that ray hits something they will walk even if the ray hits the ground. Your gonna need to make it so you hit each one separately somehow, like a button assigned to walk each different character, or check if they are hit by a Raycast (by checking the hit info when that Raycast hits something, perhaps check if it’s this.gameObject and then walk)