Refferencing to other scripts

Hello,

I’m having trouble trying to make this and I don’t really know how to do it.

What I’m trying to accomplish is this.

I’ve got a wooden box, and a character, the wooden box has a script named “Destruible” (it means that it can be destroyed, it’s not in english, i don’t think it matters really much so i kept it untranslated), and my character’s sword has a script named SwordCollision.

The SwordCollision script chechs the collisions that the sword receives. And what I’m trying to do is check when the sword collides with a object that can be destroyed (checking its Tag) and also check if the character is attacking.

If both of them are true, I try to access the other object attached script named Destruible, and access the function in it named MakeDestroy, so the object will be destroyed, and a particle explosion would be placed instead (This is what MakeDestroy function makes)

The problem is that I don’t know how to access other’s Script that has attached and execute one of it’s functions (other collider, in the function OnTriggerStay), here’s the code I’m trying to make, it isn’t working right now:

function OnTriggerStay (other : Collider) {

if(MonkeyEngine.attacking && other.CompareTag ("Destruibles"))
{other.gameObject.Destruible.MakeDestroy();}//The problem is in this line
}

Well I don’t really know how to reffer to the function of the script from the other collider object but this isn’t the right way, so if anybody can help me, I’d really appreciate it.

Thank you

Once you have some reference to the object, you can get the script by type - which for scripts is the filename without quotes or extension:

function OnTriggerStay (other : Collider) {

if(MonkeyEngine.attacking && other.CompareTag ("Destruibles"))
{
  other.GetComponent(Destruible).MakeDestroy(); //The problem WAS (I hope) in this line
}