functions being called erratically from if cases in update

i have a script that moves the camera a set amount when the player exceeds a certain distance from said camera in a given direction
i use an event to indicate when the camera moves to the next screen
however, even if the camera doesn’t move, the functions still are called constantly

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class CameraController : MonoBehaviour
{
    GameObject player;
    Vector2 playerRelative;
    public float northBoundary, southBoundary, eastBoundary, westBoundary;
    public Vector2 cameraMoveAmount;

    public static event Action OnCameraMove;
    void Start()
    {
        if(GameObject.FindGameObjectWithTag("player")) player = GameObject.FindGameObjectWithTag("player");
    
    }
    void Update()
    {
        if(!player)
        {
            if (GameObject.FindGameObjectWithTag("player")) player = GameObject.FindGameObjectWithTag("payer");
        }
        if(player)
        {
            playerRelative = - transform.position + player.transform.position;
            if(playerRelative.x < westBoundary)
            {
                Debug.Log(playerRelative);
                transform.position -= new Vector3(cameraMoveAmount.x, 0, 0);
                //ScreenFlip();
            }
            if (playerRelative.x > eastBoundary)
            {
                Debug.Log(playerRelative);
                transform.position += new Vector3(cameraMoveAmount.x, 0, 0);
                //ScreenFlip();
            }
            if (playerRelative.y < southBoundary)
            {
                Debug.Log(playerRelative);
                transform.position -= new Vector3(0, cameraMoveAmount.y, 0);
                //ScreenFlip();
            }
            if (playerRelative.y > northBoundary)
            {
                Debug.Log(playerRelative);
                transform.position += new Vector3(0, cameraMoveAmount.y, 0);
                //ScreenFlip();
            }
        }
    }

    void ScreenFlip()
    {
        //OnCameraMove.Invoke();
        Debug.Log("screen flip invoked");
    }
}

as u can probably see, even tho the parameters within the if loops are not met, the enclosed functions still get called every cycle.

i am a very very very amateur programmer, and also a bit of a dumbass, so im sorry if this question is worded poorly or has an obvious and simple answer

thank u

Incorrect. When the code inside an if block runs, it means the condition of the corresponding if clause evaluates to true. You just assume that the conditions aren’t met - but obviously they are. :wink:

Hint: learn to use the debugger. Set a breakpoint, attach debugger, enter playmode, step over code, check the values of variables.

^^ and fix that typo

Line 23 has a typo and is an excellent example of why I hate the GameObject.Find methods. They’re prone to errors thanks to the compiler not being able to identify problems in the string. It’s one of those things that you should try to get away from as soon as possible. They’re just too much of a headache.

For now while you’re learning you can just have a check directly below them that errors if it fails. I’ve also removed the if statement as there was no point to it. The this in the log command makes it possible to double click the message in the console to select the object it occurs for.

player = GameObject.FindGameObjectWithTag("player");
if (player == null) Debug.LogWarning("Failed to find player.", this);

thank u for the help, i think this will work nicely