So I’m am trying to access a variable through 2 Scripts
One script is called Add 1 per second.cs and the other one is called Coins_display.cs
second script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Add1persecond : MonoBehaviour
{
Coins_display coins_Display;
public GameObject add1persec;
void Awake()
{
coins_Display = add1persec.GetComponent<Coins_display>();
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
add1persec.coinsAmount += 1;
}
}
Coins_display script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Coins_display : MonoBehaviour
{
public static int coinsAmount;
private Text coinsCounter;
// Start is called before the first frame update
void Start()
{
coinsCounter = GetComponent();
coinsAmount = 0;
}
// Update is called once per frame
void Update()
{
coinsCounter.text = "Coins: " + coinsAmount;
if (Input.GetKeyDown(KeyCode.Space))
{
coinsAmount += 1;
}
}
}
I don’t know why it’s not working Please help!
I don’t Know How to use the tags so if it miss lead You sorry for that