C# How to move GameObject calling it by GameObject.Find(name) from another GameObject?

I have the following code:

GameObject gObj = GameObject.Find(go.name);
gObj.transform.Translate(new Vector3((float)go.position.X, (float)go.position.Y, (float)go.position.Z));

Also tried and this doesn’t seem to work either :(:

GameObject gObj = GameObject.Find(go.name);
    gObj.transform.position = new Vector3((float)go.position.X, (float)go.position.Y, (float)go.position.Z);

Nonetheless it doesn’t seem to move the game object. It finds it no problem, but it will not update the gameobject to the new vector coordinates.

Can someone please be so kind to tell me how to move a game object in this way, or similar, calling it by name? The script is being run from outside the game object it wants to move.

Thanks.

Got it, instead of using GameObject.Find() I just created a LINQ GameObject list and search through it with LINQ commands instead. Works fine so far, just a quick test really, but glad to see I can use LINQ with this. :slight_smile:

using System.Linq;

IList<GameObject> gameObjectList = new List<GameObject>();
public GameObject character;
//....
void UpdateOrAddGameObjectPosition(string name, Vector3 vector)
{
  var record = (from gol in gameObjectList where gol.name == name select gol).FirstOrDefault();
  if(record != null)
  {
       record.transform.position = vector;
  }
  else
  {
     GameObject gObj = (GameObject)Instantiate(character,vector,Quaternion.identity);
     gObj.name = name;
     gameObjectList.Add(gObj);
  }
}