I’ve been using this script to adjust the main camera to point at ALL target objects in a racing game. All was fine in 3.3 but 3.4 has thrown various errors, most of which I’ve fixed. However, this code…
var sum = Vector3(0,0,0);
for (n = 0; n < targets.length ; n++){ sum += targets[n].transform.position; }
avgDistance = sum / targets.length; var largestDifference = returnLargestDifference();
which gathers the various target Objects positions from an array and gives a focal point for the camera to LookAt now gives errors with the code:
theCamera.transform.position.z = avgDistance.z - distance + largestDifference;
and
theCamera.transform.LookAt(avgDistance);
giving the errors ‘Z’ is not a member of ‘Object’ and 'ambiguous reference ‘LookAt’ respectively.
As ‘avgDistance’ is holding an objects positional data I think it’s probably a casting error but I can’t seem to figure it.
Any help ?