Hello. I am creating a tower defence game for testing. And i run into this error: Assets/Scripts/Game Scripts/UI/Money.cs(16,25): error CS0120: An object reference is required to access non-static member `UnityEngine.Component.GetComponent(System.Type)’ what is the problem i have no idea. Here is my codes:
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 () {
GUIText.GetComponent<GUIText> ().text = "Money:" + database.money;
}
}
Database storage.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 () {
}
}
I think thats all you need. I hope we can fix this.