public class Score:MonoBehaviour{
static int gscore=0;
–
}
public class GemCollect:MonoBehaviour
{
gscore++;
}
}
Hi @thetannurathee, because you declared gscore as static in Score, you can access it’s value from GemCollect by stating
Score.gscore = or += what ever you want.
That would be the way to do it, because you have created that static variable in Score, you can access it where.
You could declare gscore in GemCollect as static if you want to access it from Score in the same way, but it doesn’t make much sense to declare both as static - though it could. It just depends what you want to do and how your scripts work together functionally.
Because all Instances of a class will share the same value of a static variable, you need to take care how you use them.