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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Moving Multiple Objects as One

Discussion in 'Scripting' started by AnnieAnn123, Jul 30, 2015.

  1. AnnieAnn123

    AnnieAnn123

    Joined:
    Jul 28, 2015
    Posts:
    7
    Hey! I have multiple objects on screen that are clones of each other. How can I move them all simultaneously up? I don't want to have each object containing a script waiting for a keypress to move up. Is there a way to have a central controller that moves all objects with a tag up? And note: multiple clones are being created every 5 seconds.
     
  2. Zk

    Zk

    Joined:
    May 25, 2013
    Posts:
    19
    You could make them all child objects of a single parent, and then move the parent object.
     
    r_u_jellis49 and yale17 like this.
  3. ADIL KHITRAN

    ADIL KHITRAN

    Joined:
    Jun 29, 2015
    Posts:
    4
    There are two option.
    1. Make All Objects Child of single Object and Move That Object.
    2. Search Object with tag in Script and Move all of that with the Following code

    Code (CSharp):
    1. GameObject[] obj=GameObject.FindGameObjectsWithTag("TestObject");
    2.         for(int i=0;i<obj.Length;i++){
    3.             obj[i].transform.position=new Vector3(0,0,0); //New Position
    4.         }
     
    yale17, tippy33 and theANMATOR2b like this.