I want to stop the camera from from following an object on the Z axis at a certain spot.
{
public float distance;
public float height;
public GameObject objectToFollow;
// Update is called once per frame
void LateUpdate()
{
if(objectToFollow == null)
return;
Vector3 destination = objectToFollow.transform.position;
destination.x = 0f;
destination.y += height;
destination.z += distance;
transform.position = destination;
}
}
You can disable the above script and it will stop receiving LateUpdate() calls from Unity.
You will need a reference to that script and then set its .enabled property to false.
Maybe an if statement will do the trick, but how do I set the position of the Z axis that it stops on?
I think you have not fully defined (at least to me) what you’re trying to do.
Do you want the tracking motion to stop completely? That’s what I suggest above.
Do you want the motion to ONLY stop on the Z axis at some point but continue tracking the X and Y axes? If so then when you reach that point, snapshot the Z value and intentionally override it in the controller.
Remember there is also Cinemachine available free from Unity (google, or get it from the package manager), which can help you define Camera volumes so the camera never goes outside of a particular area, for instance.
How do I use Cinemachine in this case?
Definitely start with some tutorials that seem to be similar to your intended use. As I said above, I suspect I don’t understand your needs because of your second post contradicting my assumptions.