accessing script components from an 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.

i suggest putting the script name in quotes, as i have never found the compnent version to work

other.GetComponent("targetscript").yougotme();

I tried both ways, but the problem lays elsewhere.

it looks like other is a collider, so…maybe try this

other.gameObject.GetComponent("targetscript").yougotme();

result is same.
The problem of the script not compiling is more based on the fact that until the script actually runs there is nothing inside the “other” variable, and therefore there is no script and no yougotme().
So the compiler answers that yougotme() is not a member of unity.

is there a specific reason you dont want to just do

Destroy(other.gameObject);

??

this script is a sample but there are going to be different behaviors inside the yougotme() script which will vary per object.
The point is to have an object trigger a behavior on contact so that the behavior can change on different targets. Also we are trying to access variables. All of this should be possible, but i’s not working because of the compile error I described.

I just tried this on regular unity and it works, so the problem only appears in unity iphone. IU’m going to move the question to iphone section then

Hi, I’m also facing smiliar problems… What I’m trying to do is when i click onto an invisible sphere on the terrain with collider from top view, it instantiate a cube with tag “Respawn” and the script “DirectionalWaypointBlue” should be acitvated. But It doesn’t seem to work even for the Debug.Log(). Any idea what is wrong? I really need help. ):

function OnCollisionEnter(collision : Collision)
{ 
    if (collision.gameObject.tag == "Respawn") {
     Debug.Log ("Function triggering."); 
       GetComponent(DirectionalWaypointBlue).enabled = true;
	  
    } 
}