title: Unity C#, How to call a function from another script to start animation?
body: <pre><code>using UnityEngine; using System.Collections;
  
  public class ClickToMoveScript : MonoBehaviour  
  {
      public string Chopping = "Chopping";
  
      public void PlayWoodCuttingAnim()   
      {       
          //Play Woodcutting Animation        
          gameObject.GetComponent&lt;Animation&gt;().CrossFade (Chopping);  
      }     
  }
  </code></pre>
  
  <p>Heres my other Script</p>
  
  <pre><code>using UnityEngine; 
  using System.Collections;
  
  public class WoodCuttingScript: MonoBehaviour  
  {
      ClickToMoveScript ClickToMove;
  
      void Start()
      {
          ClickToMove.PlayWoodCuttingAnim();  
      }  
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/wt0mN.png" alt="Unity Debugger"></p>
  
  <p>I have already added the animation inside the animation component.</p>
  
  <p>The other thing i found out is that if i call the PlayWoodCuttingAnim() function inside ClickToMove script it works fine but in the other script it dosent work.</p>
  
  <p>The error console > NullReferenceException: Object reference not set to an instance of an object.</p>
  
  <p>Any help would be greatly appreciated</p>