How do I find a GameObject by name?

Is there a way to use .name instead of .Find or .tag (cause find is slow). I want to put in a variable the name of a GO.

var Ennemy : GameObject = GameObject.Find("Ennemy");

to something like

var Ennemy : GameObject = GameObject.name("Ennemy");

But that is not the right syntax.

Thnaks

The Find function finds an object by name. If you want to find an object by something other than the name or tag, you'll have to write your own function to do it, which will likely be just as slow as Find if not slower. Like Hightree already said, if you need to access the object multiple times, just create a local variable and find it once then store it.

So instead of this:

function Update() {
    var enemy : GameObject = GameObject.Find("enemy");
    //perform operations on enemy here
}

Do something like this:

var enemy : GameObject;

function Start() {
    enemy = GameObject.Find("enemy");
}

function Update() {
    //perform operations on enemy here
}

Although if you aren't using Find every frame (or every couple of frames or something) it won't really make a difference.

You could also add some kind of registration script to your 'Enemy' GameObject, which will register your gameobject to an 'EnemyManager' singleton of your own, and replace the costly generic Find() calls by specialized EnemyManager.Find() calls .. and use whatever attribute you want (name for example) as the search key.

If Find is too slow (for instance, to use every frame), then you can use Find only once, store the GO in a local variable and reuse it all subsequent frames.

link text

@Stelimar do you know how one could you do this in c#?