calling GetComponent scripts with the same name

Hi folks,

I have a javascript named “onObject”. The script is on every gameobject at least once. But on some objects I need to have two onObject-Scripts in my inspector-stack.

When calling GetComponent(onObject) from another script, both components in the stack are called. But I need to seperate them. It’s important for me to activate the first and deactivate the second at the same time.

Any idea?

// I can’t quite figure out how your script work, but you could try something like this:

//set up the name in the editor
public var name:string;



public function deactivate(theName:string)
{
   if(name == theName)
   {
      enabled = false;
   }
}

// then you use SendMessage(name) to deactivate the script

hey RickTick,

maybe I am not getting your question properly , but how about just renaming the second copy of the script or just use one copy of the script per object and access whatever you need from that one script ?

hey RickTick,

maybe I am not getting your question properly , but how about just renaming the second copy of the script or just use one copy of the script per object and access whatever you need from that one script ?

Try to use GetComponents, instead of GetComponent.
This will return an array of components, so that you can select wich one you want to use.
Take care !