i got this cript to find all object by tag when i click button.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ButtonScript : MonoBehaviour
{
public GameObject[] Objects;
public void ResetAllBalls()
{
Objects = GameObject.FindGameObjectsWithTag("Respawn");
}
}
But how do i find the postion of all of them and set all of their position on the x axis back 100 so if 1 object is at 200 on the x its now on 100 and if one is at 150 its now at 50.
Been searching all day but cant figure it out, help is appreciated.
Thank you that work perfectly, struggle with loops tried it before and manage to make the script move the object the script was attached to backwards by how many prefabs Respawn i had, so if i had 10 it would move 100 x 10, but now it works how i want it, it moves the prefabs marked Respawn, thanks again, i post the working script here if anyone else need to use it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ButtonScript : MonoBehaviour
{
public GameObject[] Objects;
public void ResetAllBalls()
{
Objects = GameObject.FindGameObjectsWithTag("Respawn");
foreach (var obj in Objects)
{
var objPos = obj.transform.position;
var xPos = objPos.x - 100;
obj.transform.position = new Vector3(xPos, objPos.y, objPos.z);
}
}
}