title: Setting Slider value in C#
body: <p>I am trying to set a Slider value through C# code.</p>
  
  <p>I have a <code>Main.scene</code> which includes a slider called Slider.
  The main camera has a game manager script attached to it.</p>
  
  <p>The slider is not Interactable (so I can display the value but the user can't change it).  </p>
  
  <p>I defined a variable:         </p>
  
  <pre><code>[SerializeField] private Slider sliderObj;     
  </code></pre>
  
  <p>and put my slider in the inspector in this field<br>
  I have a float <code>s</code> variable that I want to reflect in the slider:  </p>
  
  <pre><code>s = player1Time / (player1Time + player2Time) * 100.0f; 
  </code></pre>
  
  <p>but when I write:</p>
  
  <pre><code>sliderObj.value = s;
  </code></pre>
  
  <p>I see this error:  </p>
  
  <blockquote>
    <p>'Slider' does not contain a definition for 'value' and no extension method 'value' accepting a first argument of type 'Slider' could be found (are you missing a using directive or an assembly reference?) [Assembly-CSharp]  </p>
  </blockquote>
  
  <p>any ideas?  </p>
  
  <p>Here is the entire script:  </p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  using UnityEngine.UI;
  
  public class GameManager : MonoBehaviour
  {
  
      public static GameManager instance = null;  //this is to create a singleton =&gt; only one instance of this script running in memory
                                                  //so we only have one Game Manager running on memory
      private int activePlayer = 1; //1 = down position 2 = up position
      [SerializeField]
      private GameObject playerObj;
      [SerializeField]
      private Text timer1Text;   //player1 timer text
      [SerializeField]
      private Text timer2Text;   //player2 timer text
      [SerializeField]
      private GameObject startBtn;
      [SerializeField]
      private Texture stopTexture;
      [SerializeField]
      private Slider sliderObj;
      private Slider sli;
      public float sli_val;
      private RawImage img;
  
      private float startTime;
  
      private bool player1Active = true;
      private static float player1Time;
      private static float lastP1Time;
      private static float player2Time;
      private static float lastP2Time;
      private bool gameOver = false;
      private bool gameStarted = false;
      private bool gameFinished = false;
  
      void Awake()
      {
          if (instance == null)
          { //check if an instance of Game Manager is created
              instance = this;    //if not create one
          }
          else if (instance != this)
          {
              Destroy(gameObject);    //if already exists destroy the new one trying to be created
          }
  
          DontDestroyOnLoad(gameObject);  //Unity function allows a game object to persist between scenes
      }
  
      public bool GameStarted
      {
          get { return gameStarted; }
      }
  
      public bool GameOver
      {
          get { return gameOver; }
      }
      public void StartGame()
      {
  
          if (!gameStarted)
          {
              gameStarted = true;
              //startTime = Time.time;
              //player1Time = startTime;
              player1Active = true;
              //select start button
              img = (RawImage)startBtn.GetComponent&lt;RawImage&gt;();
              //replace it with stop button
              img.texture = (Texture)stopTexture;
          }
          else
          {
              gameStarted = false;
              gameOver = true;
          }
  
          Debug.Log("StartGame");
      }
      public void ChangePlayer()
      {
          float ty = 0f;
          int smileyRotate = 180;
          int sliderRotate = 180;
  
          Quaternion smileyRotation = playerObj.transform.localRotation;
  
          ty = playerObj.transform.position.y * -1;
  
          if (activePlayer == 1)
          {
              player1Active = false;
              activePlayer = 2;
              smileyRotate = 180;
          }
          else
          {
              player1Active = true;
              activePlayer = 1;
              smileyRotate = 0;
          }
          playerObj.transform.position = new Vector2(playerObj.transform.position.x, ty);
          smileyRotation.x = smileyRotate;
          playerObj.transform.localRotation = smileyRotation;
      }
  
      // Use this for initialization
      void Start()
      {
  
      }
  
      // Update is called once per frame
  
      private string FormatTime(float pt)
      {
          string hours, minutes, seconds, shaon;
  
          hours = ((int)pt / 3600).ToString("00");
          minutes = ((int)pt / 60).ToString("00");
          seconds = (pt % 60).ToString("00");
          if ((pt / 3600) &gt; 1)
          {
              shaon = string.Format("{0:D1}:{1:D2}:{2:D2}", hours, minutes, seconds);
          }
          else
          {
              shaon = string.Format("{0:D2}:{1:D2}", minutes, seconds);
          }
  
          return shaon;
      }
  
      void Update()
      {
  
          float s;
          GameObject sl1 = GameObject.Find("Slider");
  
          if (GameStarted)
          {
              string zman;
              if (player1Active)
              {
                  player1Time += Time.deltaTime;  //if player 1 active update his time
                  zman = FormatTime(player1Time);
                  timer1Text.text = zman;
                  //Debug.Log("player2Time: : "+ player2Time);
              }
              else
              {
                  player2Time += Time.deltaTime;  //if player 2 active update his time
                  zman = FormatTime(player2Time);
                  timer2Text.text = zman;
                  Debug.Log("player1Time: : " + player1Time);
              }
  
              s = player1Time / (player1Time + player2Time) * 100.0f;
              //sliderObj.GetComponent&lt;Slider&gt;;
              //sliderObj.=0.5f;
              sli = GameObject.Find("Slider").GetComponent&lt;Slider&gt;();
              sli.value = s;
              sliderObj.value = s;
          }
  
      }
  }
  </code></pre>