title: How to change a parent class variable from child class in unity
body: <p>I'm just starting out with Unity, and I'm making a basic 2d game using OOP principles for the characters. 
  I've created a general enemy class called <strong>EnemyController</strong> and it has a child called <strong>BasicEnemy</strong>.</p>
  
  <p>The idea is that when the enemy is spawned (between two points, which are a bed and a bar in this case), it either moves to the left or right and starts to patrol between the objects.
  I'm using raycasting for this, and so far when the enemy hits either of those points, I've gotten the ray to flip along with the sprite. 
  I can't seem to get the sprite to move in the newly flipped direction.</p>
  
  <p>I've tried to modify the <strong>moveSpeed</strong> variable in the parent class, and I've tried to write my own movement functions <strong>LeftMove</strong> and <strong>RightMove</strong>.</p>
  
  <p>My code is below. </p>
  
  <p>This is the code for the Parent class:</p>
  
  <pre><code>public class EnemyController : MonoBehaviour
  {
      //transform for each of the enemies
      protected Transform enemyTransform;
      protected Vector2 startPosition;
      protected int damageValue, healthLevel;
      public int moveSpeed;
      protected int randNum;
      protected Rigidbody2D rb;
  
      private void Start()
      {
          enemyTransform = transform;
          startPosition = enemyTransform.position;
          rb = GetComponent&lt;Rigidbody2D&gt;();
          randNum = Random.Range(1,3);
          // Debug.Log(randNum);
  
          if(randNum == 1) {
              Debug.Log("Moves Left at the start");
          } if(randNum == 2) {
              Debug.Log("Moves Right at the start");
              Flip(); 
          }
      }
      private void FixedUpdate()
      {
          Move(); 
      }
  
      protected virtual void Move()
      {
          if(randNum == 1) {
              rb.velocity = new Vector2(-moveSpeed, rb.velocity.y);
          }
          if(randNum == 2) {
              rb.velocity = new Vector2(moveSpeed, rb.velocity.y);
          }
      }
  
      public void Flip() {
          Vector3 enemyScale = transform.localScale;
          enemyScale.x *= -1;
          transform.localScale = enemyScale;
      }
  
  }
  </code></pre>
  
  <p>This is the code for the Child class:</p>
  
  <pre><code>public class BasicEnemy : EnemyController
  {
      //Origin, Direction, Range for Raycasting.
      public Transform rayOriginPoint;
      private Vector2 rayDir = new Vector2(-1,0);
      public float range;
  
      //GameObjects that it should hit
      GameObject bar, bed;
      EnemyController parentClass;
      private void Start()
      {
          bar = GameObject.Find("minibar");
          bed = GameObject.Find("bed");
      }
  
      private void Update()
      {
          RaycastHit2D hitObject = Physics2D.Raycast(rayOriginPoint.position,rayDir,range);
          Debug.DrawRay(rayOriginPoint.position,rayDir*range);
  
          if(hitObject == true) {
              if(hitObject.collider.name == bed.name) {
                  Debug.Log(hitObject.collider.name);
                  Flip();
                  rayDir *= -1;
                  LeftMove();
              }
              if(hitObject.collider.name == bar.name) {
                  Debug.Log(hitObject.collider.name);
                  Flip();
                  rayDir *= -1;
                  RightMove();
              }
          }
      }
  
      void LeftMove() {
          rb.velocity = new Vector2(-1, rb.velocity.y);
      }
  
      void RightMove(){
         rb.velocity = new Vector2(1, rb.velocity.y);
      }
  }
  </code></pre>
  
  <p>Can someone please help me with this? 
  Thanks in advance!</p>