Hi im using this code for target two objects with the main camera but i have a problem, mi first object needs to destroyed, so when is destroyed is instanciated a new prefap but de instance of the transform is breacked i tried to find gameobjects with tag but i dont know how set transform to my first gameobject of the list. (Sorry for my english if you dont understand i´ll try to be more clear)
public List<Transform> targets;
public Vector3 offset;
private Vector3 velocity;
public float smoothTime = 0.5f;
void Update()
{
GameObject Player;
Player = GameObject.FindGameObjectWithTag("Player");
if (Player == null)
{
//instanciate transform to my first element of the list in this case Element 0.
}
}
void LateUpdate()
{
if (targets.Count == 0)
return;
Vector3 centerPoint = GetCenterPoint();
Vector3 newPosition = centerPoint + offset;
transform.position = Vector3.SmoothDamp(transform.position,newPosition, ref velocity, smoothTime);
}
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*.position);*
}
return bounds.center;
}
}