Search Unity

Skipping through a dialogue using the same (keyboard) button

Discussion in 'Scripting' started by Tidcy, May 18, 2020.

  1. Tidcy

    Tidcy

    Joined:
    Apr 15, 2020
    Posts:
    53
    hello, I’m trying to build my own dialog system, and I want to use the same button that activates it (“e”) to skip to the next lines in the dialog by pressing “e” again.
    I tried looking but only found things for the UI button.
    The way I wanna make this work is like having two game objects (that get activated by pressing “e”) and I wanna deactivate gameobject “a” by pressing “e” again. THEN I wanna deactivate game object “b” by pressing “e” again. I tried doing it but they get deactivated together at the same time.
    Thx for your time
     
  2. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    You will need to map your input to another function while the dialogue is running.
    you can do this by using a simple bool.
    Code (CSharp):
    1. bool dialogueIsRunning;
    2.  
    3. void OnEButtonPressed(){
    4. if(dialogueIsRunning){
    5. SkipDialogueLine();
    6. }else{
    7. ActivateOrDeactivateDialogue();
    8. }
    9. }
     
    Tidcy likes this.
  3. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    you can check if a is still active like this

    Code (CSharp):
    1. if (Input.GetKeyDown(KeyCode.E))
    2.         {
    3.  
    4. if(a.activeSelf == false && b.activeSelf ==false){
    5. a.SetActive(true);
    6. b.SetActive(true);
    7. }else if(a.activeSelf == true && b.activeSelf ==true){
    8. a.SetActive(false);
    9. } else if(a.activeSelf == false&& b.activeSelf ==true){
    10. b.SetActive(false);
    11. }
    12.         }
    13.  
     
    Tidcy likes this.