I am learning Unity with c#. I wrote some lines of code, so that an object moves forward while its z coordinate is less than 4, and when the z coordinate is actually 4, it prints a message to the console. Here it is:
void Update()
{
if (transform.position.z==4)
{
Debug.Log("we are here");
}
if (transform.position.z<4)
{
transform.position=transform.position+(transform.forward*Time.deltaTime);
}
}
When I run the code, the object moves until its z coordinate gets to 4, as expected. the problem is that, when it gets to 4, the console does not print the "we are here" message. Why it is not happening?