Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Trying to move a gameobject using another gameobjects position

Discussion in 'Scripting' started by MammothSaturn83, Apr 5, 2019.

  1. MammothSaturn83

    MammothSaturn83

    Joined:
    Feb 10, 2018
    Posts:
    20
    Hi, i am trying to move my gameobject "Wall" to "GhostWall"s position, but it is not working.

    Here is my script:

    public gameobject Wall;
    public gameobject GhostWall;

    public void start()
    {
    Instantiate(Wall, new Vector3(1001f, 226f, 720f), Quaternion.identity);
    Wall2.position = new Transform(GhostWall2);
    }

    Thanks Nick
     
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    Try this

    GameObject Wall2 = Instantiate(Wall, new Vector3(1001f, 226f, 720f), Quaternion.identity) as GameObject;
    Wall2.transform.position = GhostWall2.transform.position;
     
  3. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    Actually... let me try that again.

    If you're trying to make a copy of Wall and move it to GhostWall, try this:

    GameObject Wall2 = Instantiate(Wall, new Vector3(1001f, 226f, 720f), Quaternion.identity) as GameObject;
    Wall2.transform.position = GhostWall.transform.position;



    If you just want to move the current Wall to GhostWall, try this:

    Wall.transform.position = GhostWall.transform.position;
     
    MammothSaturn83 likes this.
  4. MammothSaturn83

    MammothSaturn83

    Joined:
    Feb 10, 2018
    Posts:
    20
    Thankyou i will try that
     
  5. MammothSaturn83

    MammothSaturn83

    Joined:
    Feb 10, 2018
    Posts:
    20
    Yes, thankyou that helped alot. :)