NullReferenceException: Object reference not set to an instance of an object 3 SAME ERROR

Hello. I have some errors that i cant fix i tried searching google dosent help. Moderator allow this please. These are the errors:

  1. NullReferenceException: Object reference not set to an instance of an object
    Databasestorage.Start () (at Assets/Scripts/Game Scripts/Databasestorage.cs:11)
    .2.NullReferenceException: Object reference not set to an instance of an object
    EnemyHealth.Start () (at Assets/Scripts/Game Scripts/AI/EnemyHealth.cs:13)
    .3.NullReferenceException: Object reference not set to an instance of an object
    EnemyHealth.Update () (at Assets/Scripts/Game Scripts/AI/EnemyHealth.cs:19)
    . Thats all the final number like :19 is the error line.

And here is the code:

Money.cs

using UnityEngine;
using System.Collections;

public class Money : MonoBehaviour {

	private Databasestorage database;
	// Use this for initialization
	void Start () {
	
		database = transform.Find ("Main Camera").GetComponent<Databasestorage> ();
	}
	
	// Update is called once per frame
	void Update () {
	
		GetComponent<GUIText> ().text = "Money:" + database.money;
	}
}

Databasestorage.cs

using UnityEngine;
using System.Collections;

public class Databasestorage : MonoBehaviour {

	public int money = 0;
	private EnemyHealth enemyinfo;
	// Use this for initialization
	void Start () {
	
		enemyinfo = transform.Find ("Enemy").GetComponent<EnemyHealth> ();
	}
	
	// Update is called once per frame
	void Update () {
	

	}
}

EnemyHealth.cs

using UnityEngine;
using System.Collections;

public class EnemyHealth : MonoBehaviour {
	
	public int ehealth = 100;
	public int damage = 50;

	private Databasestorage database;

	void Start () {

		database = transform.Find ("Main Camera").GetComponent<Databasestorage> ();
	}
	void Update () {

		if(ehealth < 1) {

			database.money += 1;
			Destroy(gameObject);
		}
	}

	void OnCollisionEnter (Collision col)
	{
		if(col.gameObject.name == "CannonBall(Clone)")
		{
				Destroy(col.gameObject);
				ehealth -= damage;
		}

	}

}

Thats all i think. If you need more information tell me.

Transform.Find “finds a child by name and returns it” as written in the manual : Unity - Scripting API: Transform.Find

  • So, is there an object called “Enemy” that is a child of the object to which Databasestorage.cs is attached?

  • Is there an object called “Main Camera” that is a child of the object to which EnemyHealth.cs is attached?

I bet the answer is no, which is what the errors are telling you.

You probably meant to use GameObject.Find to find any object in the scene by name or, better still, assign references via public variables in the inspector.