When i am trying to make my money variables file without attaching it to object it stuck in 5 how to fix it ? It only works when monevariables.cs is a component
moneysystem.cs attached to object called moneyonground(a basic cube ) and the money variables attaced to variablesobj in order to work
CODE GIVES ME ERROR
Moneysystem.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class moneysystem : MonoBehaviour
{
moneyvariables mv = new moneyvariables();
bool intrigger;
// Use this for initialization
void Start() {
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
intrigger = true;
}
}
private void OnTriggerExit(Collider other)
{
if (other.CompareTag("Player"))
{
intrigger = false;
}
}
// Update is called once per frame
void FixedUpdate () {
if(intrigger)
{
if (Input.GetKeyDown(KeyCode.G))
{
mv.money = mv. money + mv.moneyonpaper;
Debug.Log(mv.money);
Destroy(gameObject);
}
}
}
}
MoneyVariables.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class moneyvariables : MonoBehaviour
{
public int money;
public int moneyonpaper = 2;
public int cost;
}