title: Unity C# script variable not changing in game when changed in script
body: <p>Very new to Unity, I'm making a tactical RPG game similar to Fire Emblem. I've followed a tutorial on movement from <a href="http://www.gameprogrammingacademy.com/unity-tutorial-tactics-movement/" rel="nofollow noreferrer">this</a> website and followed everything he did.</p>
  <p>The player character can only move 5 tiles in the directions +z, -z, +x, -x on a 12x12 tile grid, however I want it to move 6. In the TacticsMove.cs script, there is this variable: <code>public int move = 5;</code> with the amount of the variable being how many tiles the player moves. I've changed the variable to <code>public int move = 6;</code> and saved the script, but everything is the exact same as before.</p>
  <p><strong>I want <code>public int move = 6</code> to allow the player to move up to 6 tiles instead of 5</strong>. There are no comments on the tutorial or youtube videos of this happening so the next place im coming to is here. My code is below, I don't know if all of this is relevant. If you need me to add/remove something, tell me.</p>
  <p>TacticsMove.cs</p>
  <pre><code>ï»¿using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class TacticsMove : MonoBehaviour 
  {
      public bool turn = false;
  
      List&lt;Tile&gt; selectableTiles = new List&lt;Tile&gt;();
      GameObject[] tiles;
  
      Stack&lt;Tile&gt; path = new Stack&lt;Tile&gt;();
      Tile currentTile;
  
      public bool moving = false;
      public int move = 6;
      public float jumpHeight = 2;
      public float moveSpeed = 2;
      public float jumpVelocity = 4.5f;
  
      Vector3 velocity = new Vector3();
      Vector3 heading = new Vector3();
  
      float halfHeight = 0;
  
      bool fallingDown = false;
      bool jumpingUp = false;
      bool movingEdge = false;
      Vector3 jumpTarget;
  
      public Tile actualTargetTile;
  
      protected void Init()
      {
          tiles = GameObject.FindGameObjectsWithTag(&quot;Tile&quot;);
  
          halfHeight = GetComponent&lt;Collider&gt;().bounds.extents.y;
  
          TurnManager.AddUnit(this);
      }
  
      public void GetCurrentTile()
      {
          currentTile = GetTargetTile(gameObject);
          currentTile.current = true;
      }
  
      public Tile GetTargetTile(GameObject target)
      {
          RaycastHit hit;
          Tile tile = null;
  
          if (Physics.Raycast(target.transform.position, -Vector3.up, out hit, 1))
          {
              tile = hit.collider.GetComponent&lt;Tile&gt;();
          }
  
          return tile;
      }
  
      public void ComputeAdjacencyLists(float jumpHeight, Tile target)
      {
          //tiles = GameObject.FindGameObjectsWithTag(&quot;Tile&quot;);
  
          foreach (GameObject tile in tiles)
          {
              Tile t = tile.GetComponent&lt;Tile&gt;();
              t.FindNeighbors(jumpHeight, target);
          }
      }
  
      public void FindSelectableTiles()
      {
          ComputeAdjacencyLists(jumpHeight, null);
          GetCurrentTile();
  
          Queue&lt;Tile&gt; process = new Queue&lt;Tile&gt;();
  
          process.Enqueue(currentTile);
          currentTile.visited = true;
          //currentTile.parent = ??  leave as null 
  
          while (process.Count &gt; 0)
          {
              Tile t = process.Dequeue();
  
              selectableTiles.Add(t);
              t.selectable = true;
  
              if (t.distance &lt; move)
              {
                  foreach (Tile tile in t.adjacencyList)
                  {
                      if (!tile.visited)
                      {
                          tile.parent = t;
                          tile.visited = true;
                          tile.distance = 1 + t.distance;
                          process.Enqueue(tile);
                      }
                  }
              }
          }
      }
  
      public void MoveToTile(Tile tile)
      {
          path.Clear();
          tile.target = true;
          moving = true;
  
          Tile next = tile;
          while (next != null)
          {
              path.Push(next);
              next = next.parent;
          }
      }
  
      public void Move()
      {
          if (path.Count &gt; 0)
          {
              Tile t = path.Peek();
              Vector3 target = t.transform.position;
  
              //Calculate the unit's position on top of the target tile
              target.y += halfHeight + t.GetComponent&lt;Collider&gt;().bounds.extents.y;
  
              if (Vector3.Distance(transform.position, target) &gt;= 0.05f)
              {
                  bool jump = transform.position.y != target.y;
  
                  if (jump)
                  {
                      Jump(target);
                  }
                  else
                  {
                      CalculateHeading(target);
                      SetHorizotalVelocity();
                  }
  
                  //Locomotion
                  transform.forward = heading;
                  transform.position += velocity * Time.deltaTime;
              }
              else
              {
                  //Tile center reached
                  transform.position = target;
                  path.Pop();
              }
          }
          else
          {
              RemoveSelectableTiles();
              moving = false;
  
              TurnManager.EndTurn();
          }
      }
  
      protected void RemoveSelectableTiles()
      {
          if (currentTile != null)
          {
              currentTile.current = false;
              currentTile = null;
          }
  
          foreach (Tile tile in selectableTiles)
          {
              tile.Reset();
          }
  
          selectableTiles.Clear();
      }
  
      void CalculateHeading(Vector3 target)
      {
          heading = target - transform.position;
          heading.Normalize();
      }
  
      void SetHorizotalVelocity()
      {
          velocity = heading * moveSpeed;
      }
  
      void Jump(Vector3 target)
      {
          if (fallingDown)
          {
              FallDownward(target);
          }
          else if (jumpingUp)
          {
              JumpUpward(target);
          }
          else if (movingEdge)
          {
              MoveToEdge();
          }
          else
          {
              PrepareJump(target);
          }
      }
  
      void PrepareJump(Vector3 target)
      {
          float targetY = target.y;
          target.y = transform.position.y;
  
          CalculateHeading(target);
  
          if (transform.position.y &gt; targetY)
          {
              fallingDown = false;
              jumpingUp = false;
              movingEdge = true;
  
              jumpTarget = transform.position + (target - transform.position) / 2.0f;
          }
          else
          {
              fallingDown = false;
              jumpingUp = true;
              movingEdge = false;
  
              velocity = heading * moveSpeed / 3.0f;
  
              float difference = targetY - transform.position.y;
  
              velocity.y = jumpVelocity * (0.5f + difference / 2.0f);
          }
      }
  
      void FallDownward(Vector3 target)
      {
          velocity += Physics.gravity * Time.deltaTime;
  
          if (transform.position.y &lt;= target.y)
          {
              fallingDown = false;
              jumpingUp = false;
              movingEdge = false;
  
              Vector3 p = transform.position;
              p.y = target.y;
              transform.position = p;
  
              velocity = new Vector3();
          }
      }
  
      void JumpUpward(Vector3 target)
      {
          velocity += Physics.gravity * Time.deltaTime;
  
          if (transform.position.y &gt; target.y)
          {
              jumpingUp = false;
              fallingDown = true;
          }
      }
  
      void MoveToEdge()
      {
          if (Vector3.Distance(transform.position, jumpTarget) &gt;= 0.05f)
          {
              SetHorizotalVelocity();
          }
          else
          {
              movingEdge = false;
              fallingDown = true;
  
              velocity /= 5.0f;
              velocity.y = 1.5f;
          }
      }
  
      protected Tile FindLowestF(List&lt;Tile&gt; list)
      {
          Tile lowest = list[0];
  
          foreach (Tile t in list)
          {
              if (t.f &lt; lowest.f)
              {
                  lowest = t;
              }
          }
  
          list.Remove(lowest);
  
          return lowest;
      }
  
      protected Tile FindEndTile(Tile t)
      {
          Stack&lt;Tile&gt; tempPath = new Stack&lt;Tile&gt;();
  
          Tile next = t.parent;
          while (next != null)
          {
              tempPath.Push(next);
              next = next.parent;
          }
  
          if (tempPath.Count &lt;= move)
          {
              return t.parent;
          }
  
          Tile endTile = null;
          for (int i = 0; i &lt;= move; i++)
          {
              endTile = tempPath.Pop();
          }
  
          return endTile;
      }
  
      protected void FindPath(Tile target)
      {
          ComputeAdjacencyLists(jumpHeight, target);
          GetCurrentTile();
  
          List&lt;Tile&gt; openList = new List&lt;Tile&gt;();
          List&lt;Tile&gt; closedList = new List&lt;Tile&gt;();
  
          openList.Add(currentTile);
          //currentTile.parent = ??
          currentTile.h = Vector3.Distance(currentTile.transform.position, target.transform.position);
          currentTile.f = currentTile.h;
  
          while (openList.Count &gt; 0)
          {
              Tile t = FindLowestF(openList);
  
              closedList.Add(t);
  
              if (t == target)
              {
                  actualTargetTile = FindEndTile(t);
                  MoveToTile(actualTargetTile);
                  return;
              }
  
              foreach (Tile tile in t.adjacencyList)
              {
                  if (closedList.Contains(tile))
                  {
                      //Do nothing, already processed
                  }
                  else if (openList.Contains(tile))
                  {
                      float tempG = t.g + Vector3.Distance(tile.transform.position, t.transform.position);
  
                      if (tempG &lt; tile.g)
                      {
                          tile.parent = t;
  
                          tile.g = tempG;
                          tile.f = tile.g + tile.h;
                      }
                  }
                  else
                  {
                      tile.parent = t;
  
                      tile.g = t.g + Vector3.Distance(tile.transform.position, t.transform.position);
                      tile.h = Vector3.Distance(tile.transform.position, target.transform.position);
                      tile.f = tile.g + tile.h;
  
                      openList.Add(tile);
                  }
              }
          }
  
          //todo - what do you do if there is no path to the target tile?
          Debug.Log(&quot;Path not found&quot;);
      }
  
      public void BeginTurn()
      {
          turn = true;
      }
  
      public void EndTurn()
      {
          turn = false;
      }
  }
  </code></pre>
  <p>Tile.cs</p>
  <pre><code>ï»¿using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class Tile : MonoBehaviour 
  {
      public bool walkable = true;
      public bool current = false;
      public bool target = false;
      public bool selectable = false;
  
      public List&lt;Tile&gt; adjacencyList = new List&lt;Tile&gt;();
  
      //Needed BFS (breadth first search)
      public bool visited = false;
      public Tile parent = null;
      public int distance = 0;
  
      //For A*
      public float f = 0;
      public float g = 0;
      public float h = 0;
  
      // Use this for initialization
      void Start () 
      {
  
      }
      
      // Update is called once per frame
      void Update () 
      {
          if (current)
          {
              GetComponent&lt;Renderer&gt;().material.color = Color.magenta;
          }
          else if (target)
          {
              GetComponent&lt;Renderer&gt;().material.color = Color.green;
          }
          else if (selectable)
          {
              GetComponent&lt;Renderer&gt;().material.color = Color.blue;
          }
          else
          {
              GetComponent&lt;Renderer&gt;().material.color = Color.white;
          }
      }
  
      public void Reset()
      {
          adjacencyList.Clear();
  
          current = false;
          target = false;
          selectable = false;
  
          visited = false;
          parent = null;
          distance = 0;
  
          f = g = h = 0;
      }
  
      public void FindNeighbors(float jumpHeight, Tile target)
      {
          Reset();
  
          CheckTile(Vector3.forward, jumpHeight, target);
          CheckTile(-Vector3.forward, jumpHeight, target);
          CheckTile(Vector3.right, jumpHeight, target);
          CheckTile(-Vector3.right, jumpHeight, target);
      }
  
      public void CheckTile(Vector3 direction, float jumpHeight, Tile target)
      {
          Vector3 halfExtents = new Vector3(0.25f, (1 + jumpHeight) / 2.0f, 0.25f);
          Collider[] colliders = Physics.OverlapBox(transform.position + direction, halfExtents);
  
          foreach (Collider item in colliders)
          {
              Tile tile = item.GetComponent&lt;Tile&gt;();
              if (tile != null &amp;&amp; tile.walkable)
              {
                  RaycastHit hit;
  
                  if (!Physics.Raycast(tile.transform.position, Vector3.up, out hit, 1) || (tile == target))
                  {
                      adjacencyList.Add(tile);
                  }
              }
          }
      }
  }
  </code></pre>
  <p>PlayerMove.cs</p>
  <pre><code>ï»¿using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class PlayerMove : TacticsMove 
  {
  
      // Use this for initialization
      void Start () 
      {
          Init();
      }
      
      // Update is called once per frame
      void Update () 
      {
          Debug.DrawRay(transform.position, transform.forward);
  
          if (!turn)
          {
              return;
          }
  
          if (!moving)
          {
              FindSelectableTiles();
              CheckMouse();
          }
          else
          {
              Move();
          }
      }
  
      void CheckMouse()
      {
          if (Input.GetMouseButtonUp(0))
          {
              Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  
              RaycastHit hit;
              if (Physics.Raycast(ray, out hit))
              {
                  if (hit.collider.tag == &quot;Tile&quot;)
                  {
                      Tile t = hit.collider.GetComponent&lt;Tile&gt;();
  
                      if (t.selectable)
                      {
                          MoveToTile(t);
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  <p>Im using unity version 2019.3.12f1.</p>
  <p>Any help is appreciated.</p>