Hello,
I have a problem which I can no solve. I get this error: NullReferenceException: Object reference not set to an instance of an object
when I select something on my game the code is here.
using UnityEngine;
using System.Collections;
public class Buy : MonoBehaviour {
public Coins coins;
// Use this for initialization
void Start () {
coins = GetComponent<Coins> ();
}
// Update is called once per frame
void Update () {
}
void OnMouseEnter()
{
renderer.material.color = Color.red;
}
void OnMouseExit()
{
renderer.material.color = Color.white;
}
void OnMouseUp()
{
if (coins.amountOfCoins == 10)
{
GameObject.Find("Cost_2").renderer.enabled = false;
}
}
}
The error is at the if statement.
Any help would be appreciated.