Suppose the script finds the center point between two objects on the map.
public List<Transform> targets;
Vector3 GetCenterPoint() { if (targets.Count == 1) { return targets[0].position; } var bounds = new Bounds(targets[0].position, Vector3.zero); for (int i=0; i < targets.Count; i++) { bounds.Encapsulate(targets[i].position); } return bounds.center; }
But how to make finding a center between objects, if they only appeared on the map? How to create a prefab on the map:
if (!spawned) { if (Input.GetKey(KeyCode.Q)) { Instantiate(myPrefab, new Vector3(0, 0, 0), Quaternion.identity); spawned = true; } }