Search Unity

Selecting a variable in the inspector

Discussion in 'Scripting' started by mrgolemm, Jan 20, 2020.

  1. mrgolemm

    mrgolemm

    Joined:
    Jun 25, 2019
    Posts:
    16
    I have a simple code. I need so that in place of "var" I can select a variable in the inspector that will replace the variable "var".

    Code (CSharp):
    1.     public GameObject showElement;
    2.  
    3.     void ShowElement ()
    4.     {
    5.         if (var == 0)
    6.         {
    7.             showElement.SetActive(false);
    8.         }
    9.     }
     
  2. happy-tree

    happy-tree

    Joined:
    Jan 20, 2020
    Posts:
    8
    Add another public variable.

    Code (CSharp):
    1. public GameObject showElement;
    2. public int variable = 0;
    3.  
    4. void ShowElement ()
    5. {
    6.     if (variable == 0)
    7.     {
    8.         showElement.SetActive(false);
    9.     }
    10. }
    Now you can change the variable in the inspector.
     
  3. Ardenian

    Ardenian

    Joined:
    Dec 7, 2016
    Posts:
    313