How can I make the flag to be true and false but each time only once?


using System.Collections; using System.Collections.Generic; using UnityEngine; using Cinemachine;  public class UnlockCrate : MonoBehaviour {     public Animation anim;     public IKControl ikControl;     public GameObject securityKeyPad;     public CinemachineVirtualCamera virtualCam;     public CinemachineFreeLook freeLookCam;     public CamerasControl camerasContorl;      private bool playAnimOnce = false;      private void Update()     {          if (!playAnimOnce)         {             if (ikControl.handFinishedMove == true)             {                 securityKeyPad.SetActive(true);                 virtualCam.enabled = true;                 freeLookCam.enabled = false;                 Cursor.visible = true;                 camerasContorl.enabled = false;                             }              playAnimOnce = true;         }         else if (playAnimOnce)         {             securityKeyPad.SetActive(false);             virtualCam.enabled = false;             freeLookCam.enabled = true;             Cursor.visible = false;             camerasContorl.enabled = true;             playAnimOnce = false;         }     } } 

The problem is that the playAnimOnce flag is false then true then false then true all the time. I want that if it’s false do something and then only if it’s true do something else.0

Should I use another flag helper and how ?