problem SendMessage

Hello I wanted to know your opinion on a script that I want to “slow” start by saying that it is a game that I’m developing on Android but the issue does not affect the touch (that works fine) the problem is in a passage of data. I want that when I hit the red ball (array number 3) and this will sound increases. As if I’m wrong color decreases the score. To decrease the score works well but sometimes difficult to detect when the ball is the right one. I attached the script touch to the room to detect the touch. I added an if statement that if I touch the ball sends me to functio Tablet (); here are the codes. I hope you can help me. Thank you =)

Touch ok:

#pragma strict

function Update () 
{
   //loop through all registered touches
   for (var i = 0; i < Input.touchCount; ++i) 
   {
     if (Input.GetTouch(i).phase == TouchPhase.Began) 
     { 
       var hit : RaycastHit;
       var ray = Camera.main.ScreenPointToRay (
Input.GetTouch(i).position
);
       if (Physics.Raycast (ray, hit, 10000))
       {
          //Destroy(hit.transform.gameObject);
          gameObject.Find("Sphere(Clone)").SendMessage("Tablet");  //if I click on a ball I run the function tablet
          
       }
       
     }
   }
}

function Tablet:

#pragma strict

var texBall : Texture[] = new Texture [5];

var randomtex : int;

function Start(){

textureRandom(); //esegui la funzione textureRandom

 
}

function update(){
collider.enabled = true;


}

function textureRandom(){

while(true){ //finchè è vero esegui il ciclo
    
    yield WaitForSeconds(1); //aspetto 1 secondo e cambio colore alla mesh
    
     // variabile randomColor
    
     randomtex = Random.Range(0, texBall.length); //random della variabile cambiaColore
    
      
   renderer.material.mainTexture= texBall[randomtex]; // lo assegno alla variabile randomColor
    
}
}

function Tablet(){ //se collider attivo 

if(randomtex == 3){ //color red texture

Destroy(gameObject);

gameObject.Find("Main Camera").SendMessage("aggiorna"); //does not work
gameObject.Find("Main Camera").SendMessage("sound"); //does not work
}


else{
Destroy(gameObject);
gameObject.Find("Main Camera").SendMessage("decrementa"); //works well


}


}

Try this instead, then you are sure its the one you hit that will be called:

 if (Physics.Raycast (ray, hit, 10000))
{
          hit.transform.gameObject.SendMessage("Tablet");
}

thank you very much it works! : D

No problem! The problem with the other method is that when you call Find and a name then you will get one returned from the scene heirachy and not the one you always want. Will really only work if you only have one instance with the name in the scene.