I don't understand why "Null pointer Exception" in Unity? : <p>in my C# lives class I have a class attribute:
public int life = 0;
and in my C# loose class (so, another script), I want to access to my life attribute of my lives class, but i don't succeed, how to do it ?</p>

<p>When I do</p>

<pre><code>var lv = new lives ();
int lv1 = lv.life;
</code></pre>

<p>It shows me that Unity does not allow. I MUST use GetComponent</p>

<p>so I do with get component</p>

<pre><code>var lv = gameObject.GetComponent&lt;lives&gt; ();
int lv1 = lv.life;
</code></pre>

<p>And I have a null pointer exception, so it is not understandable ?</p>
