So i have a script for whenever the player looks at the enemy it does something. I want to increment a variable once every time the onScreen boolean has is true, the problem is that since the teleport function has to be in update it increments it every frame.
void Teleport()
{
Vector3 screenPoint = testCamera.WorldToViewportPoint(transform.position);
bool onScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;
if (timesLookedAt >= 3 && !onScreen)
{
Debug.Log("Teleport");
// Teleport away
}
}