Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Bool not triggering script

Discussion in 'Scripting' started by FlagrentPossum, Oct 4, 2023.

  1. FlagrentPossum

    FlagrentPossum

    Joined:
    Jun 17, 2023
    Posts:
    4
    Hey guys for some reason my snapShotEnder() will not trigger even though the bool gets set active in my other script...

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class PasswordCheck : MonoBehaviour
    7. {
    8.     public InputField USB_Drive;
    9.     public GameObject ImageWindow;
    10.     public GameObject USBWindow;
    11.     public string correctPassword = "f/11";
    12.     public AudioClip Error;
    13.     public float volume = 1;
    14.     public GameObject HintText;
    15.     private int SubmissionCount = 0;
    16.     public Camera Camera2;
    17.     public Camera PlayerController;
    18.     public bool EndScenario_Snapshot = false;
    19.     public GameObject CamSwitcher;
    20.    
    21.     private void Start()
    22.     {
    23.         USB_Drive.onEndEdit.AddListener(delegate { CheckPassword(USB_Drive); });
    24.     }
    25.  
    26.     private void CheckPassword(InputField inputField)
    27.     {
    28.         string enteredPassword = inputField.text.ToLower();
    29.         string correctPasswordLower = correctPassword.ToLower();
    30.  
    31.         if (enteredPassword.Equals(correctPasswordLower))
    32.         {
    33.             ImageWindow.SetActive(true);
    34.             USBWindow.SetActive(false);
    35.             frameStall();
    36.         }
    37.         else
    38.         {
    39.             ImageWindow.SetActive(false);
    40.             inputField.text = string.Empty;
    41.             AudioSource.PlayClipAtPoint(Error,transform.position,volume);
    42.             SubmissionCount++;
    43.            
    44.         }
    45.         if(SubmissionCount == 3)
    46.         {
    47.             HintText.SetActive(true);
    48.         }
    49.     }
    50.    
    51.     public void frameStall()
    52.     {
    53.        
    54.         StartCoroutine(discoveredPhoto());
    55.     }
    56.    
    57.     IEnumerator discoveredPhoto()
    58.     {
    59.         CamSwitcher.SetActive(false);
    60.         Cursor.visible = false;
    61.         Cursor.lockState = CursorLockMode.Locked;
    62.         yield return new WaitForSeconds(4f);
    63.         Camera2.enabled = false;
    64.         PlayerController.enabled = true;
    65.         EndScenario_Snapshot = true;
    66.     }
    67.    
    68. }
    69.  
    70. /// EndScenario_Snapshot on true will trigger another script that commence the confession state
    71. ///

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6.  
    7. public class finalSnapShotConfession : MonoBehaviour
    8. {
    9.     public GameObject InputField;
    10.     public PasswordCheck PasswordCheck;
    11.     private string desktopSceneName = "Desktop";
    12.  
    13.     public void snapShotEnder()
    14.     {
    15.        
    16.     if (PasswordCheck.EndScenario_Snapshot)
    17.     {
    18.        
    19.         InputField.SetActive(false);
    20.         //// add func here later for to start the animation and speech
    21.         endsceneVoid();
    22.     }
    23. }
    24.  
    25.     public void endsceneVoid()
    26.     {
    27.         StartCoroutine(endscene());
    28.     }
    29.  
    30.     IEnumerator endscene()
    31.     {
    32.         yield return new WaitForSeconds(7f);
    33.         SceneManager.LoadScene(desktopSceneName);
    34.     }
    35.    
    36.    
    37. }
    38.  
     
  2. FlagrentPossum

    FlagrentPossum

    Joined:
    Jun 17, 2023
    Posts:
    4
    geez nvm needed Update() to constantly check
     
  3. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,448
    Hi,

    First, you should use camelCase for your variables, "public PasswordCheck PasswordCheck;" is awfully confusing.
    Second, shouldn't the same:

    public PasswordCheck PasswordCheck;

    be

    public PasswordCheck passwordCheck =new() ;

    in fact?
     
  4. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,448
    Anyway, think about using camelCase. :)
     
  5. zulo3d

    zulo3d

    Joined:
    Feb 18, 2023
    Posts:
    510
    I use rAnSomCaSE
     
    Kurt-Dekker and Nad_B like this.
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    Chaotic Evil. ;)
     
    zulo3d likes this.
  7. Nad_B

    Nad_B

    Joined:
    Aug 1, 2021
    Posts:
    303
  8. FlagrentPossum

    FlagrentPossum

    Joined:
    Jun 17, 2023
    Posts:
    4
    Lol yea was preparing for the roasts on that . im in the bad habit of throwing out whatever and cleaning up later
     
    Kurt-Dekker likes this.