accessing script components from external objects

here is a simplification of the problem I'm having.

object one has a script named targetscript:

function yougotme()
{
Destroy(gameObject) ;
}

object two has a script that on collision should collect what the object hit is (one), get the script associated and call a function in it.

function OnTriggerEnter (other : Collider)
{
var activatescript = other.GetComponent(targetscript);
if (other.GetComponent(targetscript))
{
other.GetComponent(targetscript).yougotme();
}

}

The problem is that at compile time, such collision does not exist yet and the compiler can not find the yougotme() component. The error is "'yougotme' is not a member of 'UnityEngine.Component'"

Our point here is to retain the triggering of the action on the weapon (object one) and the resulting action on the receiving object (object two), so that we can have multiple weapons trigger actions that are specific to multiple targets. We are certainly open to another strategy to the same final goal.

Any help is appreciated.

You can simplify the getcomponent part to just this (which stops you getting it 3 times o.o)

var activatescript : targetscript = other.GetComponent(targetscript);
if (activatescript != null)
{
    activatescript.yougotme();
}

Assigning to a variable with the right type is the key you were missing - after that, you just use it as normal

The error is not because the collision hasn't happened yet but because you're using a strictly typed environment (either iphone, or #pragma strict on desktop). If you want to call a function on a variable, that variable has to be the right type - GetComponent is just returning a basic Component reference to you, so you need to type it manually

as Mike said. GetComponent returns a component reference and the result need to be casted to the correct type. in unity 3 you can access generic versions that return the correct type. in C# and strictly typed js (iphone or pragma_strict) you need to cast it yourself. in C# you should do something like

targetscript t;
t = (GetComponent(typeof(targetscript)) as targetscript);
//or use the generic version
t = GetComponent<targetscript>();
//and then 
t.yougotme();

try to code your names like YouGotMe() and TargetScript. it's really more readable for you and others. the js syntax is what Mike said.