asseign script to resources

hello,
How can I asseign a script to a prefab stored in a resource file.
This prefab appears during the game so it’s not visible in my hierarchy in the scene view.
I suspect that I can speak with this prefab using code but I don’t know how I can provide the prefab with code.

greetz

During the game I get a clone of this prefab in the hirarchie listing

Use GameObject.FindWithTag or GameObject.Find.

I new that I could find him like that but how can I for example tell to my prefab that he had to play a audio source that is already asseigned to this prefab before he comes into the game. Cause if I put the code into my first person controller for example I get the message that there is no audiosource on the controller . That is offcourse not the meaning also, but how can I handel over the audiosource of the prefab I found ?

Just put an audio source onto the original prefab and set it to “Play on awake” or the option that looks similar.

already thanks for your efforts ,

In my project if I walk over coins the prefab comes in the game,
I have already asseigned audiosource in the original prefab and it stands on play on awake .
Now, I have a few of that kind of prefabs in my scene. The raison why I wanted to now if I could code my prefab is because I want to shut down the music when my first person controller isn’t in a specific area around my prefab. Also I want to hang a gui text on this prefab so when my controller raycast the prefab , the gui pops up .

Is it possible to give some hints how I approche this situation best ?

the strange thing is that raycast doesn’t seem to work with my prefabs, if I test the same code with other gameobjects it work well.
Someone an explenation for that ?

thanks in advance

this is the code I use for raycasting my prefab :

function Update(){

var hit2:RaycastHit;

if(Physics.Raycast(transform.position, transform.forward, hit2, 5))

{

if (hit2.collider.gameObject.name ==“mijn prefab(Clone)”)

{

print(“de deur”);

}

}