I would like to acces a variable called cooldown from another script called BulletScript and i cant figure out what's wrong with my codes. Here are my codes: 1st:
using UnityEngine;
public class gunMechanic : MonoBehaviour
{
private BulletScript bulletScript;
private void Awake() {
bulletScript = GameObject.FindObjectOfType<BulletScript>();
Debug.Log(bulletScript.cooldown);
}
}
2nd:
using UnityEngine;
public class BulletScript : MonoBehaviour
{
public float cooldown = 1;
}
Here are lots of different possible reasons for your issue. Try adding [SerializeField] before
private BulletScript bulletScript;and directly serialize object with your script.It's possible that you:
Awake()and/orStart();If you can provide any logs or more information about your project startup.