title: Unity 3D C# Script - my private member seems to just be alternating between 0 an the correct value
body: <p>I have a script in my unity application (called cubemove.cs).</p>
  
  <p><strong>It has the private member:</strong></p>
  
  <pre><code>private float z_ref;
  </code></pre>
  
  <ul>
  <li>Inside my <code>void Awake()</code> I have a line for initialization: <code>z_ref = (float) 0.0;</code></li>
  </ul>
  
  <p><strong>I have a button in my application set to run the following function onclick from cubemove.cs</strong></p>
  
  <pre><code>public void zeroZ()
  {
      z_ref = (float) 45.0;
  }
  </code></pre>
  
  <ul>
  <li>My <code>void Update()</code> contains <code>Debug.Log("z_ref: " + z_ref.ToString());</code></li>
  </ul>
  
  <p>When I run the application and view the debugging output, first it's only printing <code>z_ref: 0</code>. This is expected as that is what I initialized the value to. Then when I hit the button in the application (which results in zeroZ() being executed), I <em>expect</em> it to now print 45. Instead it alternates between 45 and 0.</p>
  
  <p><a href="https://i.stack.imgur.com/ZUeuB.png" rel="nofollow noreferrer">Here is the image of the debug output after the button press</a></p>
  
  <ul>
  <li>Prior to pressing the button it was all 0's.</li>
  </ul>
  
  <p>My original program actually had more code when I first encountered this issue with my z_ref randomly changing (it wasn't fixed to 45, zeroZ() was a more complex function etc). However even after I changed my cubemove.cs file to the following code below, I still see this exact same behavior of z_ref alternating between 0 and the value it's supposed to be.</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  
  public class cubemove : MonoBehaviour
  { 
      private float z_ref;
  
      void Awake()
      {
          z_ref = (float) 0.0;
      }
      void Start()
      {
      }
      void Update()
      {
          Debug.Log("z_ref: " + z_ref.ToString());
      }
      public void zeroZ()
      {
          z_ref = (float) 45.0;
      }
  }
  </code></pre>
  
  <p>After <code>zeroZ()</code> is called there should no reason z_ref should ever show up as any value other then 45. What exactly is going on here?</p>
  
  <p>In case it is relevant, my build target is android (the debug output image is from logcat).</p>