Hi. Im getting this error: NullReferenceException: Object reference not set to an instance of an object
Coins.OnTriggerEnter2D (UnityEngine.Collider2D col) (at Assets/Scripts/Coins.cs:25) And it points at this script. I’m quite new to unity and C# so it might be obvious.
using UnityEngine;
using System.Collections;
public class Coins : MonoBehaviour {
public GUIText cointext;
public CoinSpawn coinSpawn;
public int curCoins;
public int maxCoins = 10;
void Update (){
cointext.text = "Current Coin " + curCoins + "/" + maxCoins;
if (curCoins > maxCoins) {
curCoins = maxCoins;
}
}
void OnTriggerEnter2D(Collider2D col){
Debug.Log("träffar pengen");
if (col.gameObject.tag == "Coin") {
Destroy (col.gameObject);
curCoins++;
coinSpawn.spawning = false;
}
}
}`