So I have this static variable
public class GenerateCupScript : MonoBehaviour {
public static string objectName;
public void Start () {
objectName = "Test";
}
}
A script calling the variable
public class WaterTapScript : MonoBehaviour{
public string objectName;
void Start() {
objectName = GenerateCupScript.objectName;
}
}
And another script calling the same variable
public class BarForCup: MonoBehaviour{
public string objectName;
void Start() {
objectName = GenerateCupScript.objectName;
}
}
The problem is the WaterTapScript can call the value from the GenerateCup but the BarForCup can’t do that. If the BarForCup call GenerateCupScript.objectName it will return null, but the WaterTapScript will return “Test”. And this is how I tried to fix the problem but none work
1
attaching BarForCup
script to the same object the
GenerateCupScript is attached
2
attaching BarForCup script to the same
object the WaterTapScript is
attached
3
use Awake
4
public string objectName = GenerateCupScript.objectName;
5
call it at the same time in Awake, Start and using 4