title: NullReferenceException: Object reference not set to an instance of an object in unity 3D trying to make a function
body: <p></p>
  
  <pre><code> using UnityEngine;
  using System.Collections;
  [RequireComponent(typeof(flipPlayer))]
  public class enemyInstantiate : MonoBehaviour 
  {
      public GameObject[] enemies;
      public Transform enemyPos;
      public GameObject enemyClone;
  
  
  
      void Start()
      {
  
          enemyPos = GameObject.Find("enemySpawn").transform;
          enemyClone = GameObject.FindGameObjectWithTag("Player");
          enemySpawn();
          flip();
      }
  
      public void enemySpawn()
      {
  
          int enemyIndex = Random.Range(0, enemies.Length);
          Instantiate(enemies[enemyIndex], transform.position, transform.rotation);
  
  
      }
      void flip()
      {
  
          enemyClone.GetComponent&lt;flipPlayer&gt;().enabled = true;
  
      }
  
  }
  </code></pre>
  
  <blockquote>
    <p>NullReferenceException: Object reference not set to an instance of an object
    enemyInstantiate.flip () (at Assets/Scripts/enemyInstantiate.cs:32)
    enemyInstantiate.Start () (at Assets/Scripts/enemyInstantiate.cs:18)</p>
  </blockquote>
  
  <p>i'm pretty new to Unity 3D 
  And still having trouble, can you please help out with what the problem is and why am i getting a nullReferenceException.</p>
  
  <p>The error occurs in the line (enemyClone.GetComponent().enabled = true;).</p>