How do I change an object's position upon triggering a function?

I just wanna do a simple from its current point disappear and appear at another point. i cant seem to get this code to work. or is it even right? can someone correct me?

function accepted(){
    GameObject.Find("Item_myObjectName").transform.position = Vector3(28.2, -0.9, 2.1);
}

EDIT:

ok pretty much it's like that, I just wanna simply shift the cube's position to the coords i want when I accept a job. I'm not using a drag and drop prefab in the IDE as it is a added component in another script.

function OnAccept(id:int){
    if(id==100){
        Debug.Log("quest 100 is accepted");
        GameObject.Find("myCube").transform.position = (28.2, -0.9, 2.1); 
    } 
} 

Edit2:

Yes, the Debug log does print out, and there are no errors either. But the cube doesn't transform and remains at its initial spot.

This is vaguely right, however without knowing more about exactly what you want to achieve, it's difficult to be of more help.

It's probably not really the best way of doing whatever it is you want to do.

Bearing in mind there are always exceptsions, it's usually better to:

  • Use dragged references in the IDE, rather than using GameObject.Find().

  • Use a reference to an empty game object as a dummy position marker, rather than hard-code values into your script.

If you edit your question to give a little more information, maybe we can give you further advice on this disappearing and appearing that you want to achieve.

You'd probably be better off saving a reference to your new object and using that rather than using GameObject.Find(). It is fairly expensive, and I have not had luck using it to locate objects created with Instantiate.

I'm new to Unity, but I've noticed that when I create objects with Instantiate, they have the name PrefabName(Clone) instead of just PrefabName. Instead of fiddling with trying to use that name, or renaming my new objects, I just saved off a reference to get at my dynamic object later without the need of a Find().