How do you access a script if you don't know it's name?

I want to be able to link one script to another in the same way you can access GameObjects or components from scripts:

var myObject : GameObject;

If I put this at the top of my script this allows me to set the GameObject in the unity editor. How would I do the same thing for a script if I don't always know what it's name is? It could vary from object to object...

Alright, I see, okay, so, each object that has a damage receive script, has a function, that controls that objects health...

So, I'd suggest looking at Broadcast message, and use that, as you can "Broadcast" a message to that function, and change a value in it, being the health of the object, then that'll reduce the amount of health...

I think this is what you're looking for...

Here's a link to the API:

That should help you, it might take a couple tests to get right, but hope it helps.

Have a good new year!

All scripts have to derive from MonoBehaviour, so you can do this:

var script : MonoBehaviour;

However, I can't think of why you'd want to do that. Additionally, you have to drag a game object onto that slot, not a script from the project pane, because what the variable does, is hold a reference to a particular instantiated class. So, you can only get a reference to the first one attached to a Game Object, unless you set the variable in code.

Edit: Okay, I read your rationale for this. The above won't help you, but something very similar will. You just need to create a new class, that is derived from MonoBehaviour, that all the damage scripts also derive from.

First, create a base class for all of your damage scripts to derive from:

class Damage extends MonoBehaviour {

public function GetHurt () {};


GetHurt is "abstract", in that it doesn't do anything here, but can be overridden in scripts that derive from it. You'll define what it does in the derived classes, so, for example:

class MuppetDamage extends Damage {

function GetHurt () {
    lifePoints -= Mathf.Infinity;


To assign any type of Damage script, that is, anything that derives from it, you can create a variable that holds a Damage, like so:

var damage : Damage;

function Hurt () {

and you can, for example, drag a MuppetDamage onto the damage variable slot, in the Inspector.

The quick and easy way is to use a string and just call GetComponent using it.

how do you make a script if you don’t want to because its due tody

how do you make a easy script when its due today