Raycast problem, i think

have problem using this script on differents buttons, when i touch one button it seam that i touch all the buttons at same time.

what i want is to have a generic script to set diferent cameras for diferent buttons using same script.

var Main_camera : Transform;
var GoToCamera: Transform;

function Update(){
if(Input.touchCount > 0)
{
var hit : RaycastHit;
var vektor = Vector3(Input.GetTouch(0).position.x,Input.GetTouch(0).position.y,0f);
var ray : Ray = Camera.main.ScreenPointToRay (vektor);
if (Physics.Raycast(ray, hit, Mathf.Infinity))
{
Main_camera.position = Vector3.Lerp(Main_camera.position, GoToCamera.position, Time.deltaTime * 4);
}
}
}

Is the device your testing on running ICS 4.0.3?

Well, to clarify what you’ve coded:

If there is a touch on the screen, see if there is anything under the touch point, if anything has been hit, move the camera to the “GoToCamera”.

If this script is attached to every button, it’s not surprising they’re all being activated, they’re all testing for whether you’ve pressed anything, not just themselves.

I’d use collider.Raycast instead of Physics.Raycast, that way you’re only testing against the collider for that button, and not just everything in the scene.