When i click on Object, .. raycast help!

Hey,

I’m new in programming Java and speaking english, I’m from germany… So I hava this problem:

I’m making a horror game and I want to create objects like a taclight, doors and other things… But I want these objects to start the function “ClickOnObject” when clicking them… i have a raycast, but i don’t know how to do that, so please help me. It would be great when i could copy for example the doors, as many times as i want and everytime the clicked door opens, the taclight or paper or what else will do “ClickOnObject”… Is that possible? Thanks

this is in C# but its an example of a door in front of you being found and the player clicking.

Ray MyRay;
RayCastHit HitInfo;

//cast from the cameras postion
MyRay.origin = Camera.main.transform.position;

//cast directly out in front of the camera
MyRay.direction = Camera.main.transform.forward;


physics.raycast(Myray, out HitInfo);

if (HitInfo)
{
  if(HitInfo.gameobject.tag == "Door")
  {
    if(Input.GetMouseButtonDown(0))
     { 
       someone just clicked and a door is in front of you 
     }
   }
}

Tank you, but i explain my problem

I have a door prefab ( “Door” ) with a object in it ( “Door_1”) with a door object in it…

so when i click the “Door” i want “Door_1” to start the animation “Open”…

But just the door i clicked has to start the animation, you unsterand?

thanks