Search Unity

Resolved Altering Script to Disable UI Toggle with Key Press

Discussion in 'Scripting' started by esrevin, Mar 20, 2023.

  1. esrevin

    esrevin

    Joined:
    Feb 4, 2021
    Posts:
    2
    Hi guys, I completed the following tutorial -


    It goes through the process of scripting flashlight mechanics.

    At the moment the UI can only be seen when the 'F' key is pressed. I was wondering how can I alter the code so that the UI elements of the flashlight are always visible and do not need a switch or toggle 'on' to be seen? It would mean a lot if I can get a hand with this.

     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Right now, the canvas group's alpha is being changed. So, there are a few ways around it. The simplest way is just make a second canvas for your flashlight elements so the flashlight UI doesn't get turned off but everything under the main canvas does.

    There is nothing wrong with having multiple canvases.
     
    esrevin likes this.
  3. All_American

    All_American

    Joined:
    Oct 14, 2011
    Posts:
    1,528
    Or separate everything with panels.
     
    esrevin likes this.
  4. esrevin

    esrevin

    Joined:
    Feb 4, 2021
    Posts:
    2
    Hi guys, I appreciate the replies. I fixed the issue by commenting out the lines of code 197 - 216 that involve the canvas and in the inspector I made sure the alpha group was set 1. Seemed to do the job. Thanks for the suggestions!