I have an integer(levelstatus
) in class A(LevelSelectScene
) and I want to change it in class B(GameScene
), is it possible?
here is my code:
(Code in GameScene)
public class levelComplete()
{
levelSelectScene.getInstance.levelstatus=1;
}
LevelSelectScene
has an public integer levelstatus
.
and after an event happens, levelComplete
will trigger and will change the value of levelstatus
from null to 1.
You need to make the variables in class aaa as class variables, and then you can use these variables of class aaa in class bbb by using object of class aaa. e.g. aaa obj2=new aaa();
There's a few ways of updating instance variables in C#: Using properties or setters like in Java or instance methods. Following code shows you a few of those. This is the object-oriented way of doing things. As for global variables in the sense of application-wide variables, you can refer to this.
Yes.
Make your levelstatus
variable as static
.
Because I guess you need to change that variable in each level class.
That means,you are wanting to access that variable through out the whole Game(All levels).
And also,Declare that variable in a Util
class(proposing a name LevelUtil
),Since it wont attach to a single level.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With