what i want is:
void Update {
If ( fire method is happend then start the water method)
}
void Fire ()
{
fire -= 1;
}
void water ()
{
water += 1;
}
(this is just a example script )
what i want is:
void Update {
If ( fire method is happend then start the water method)
}
void Fire ()
{
fire -= 1;
}
void water ()
{
water += 1;
}
(this is just a example script )
This is better achieved with a really simple state-machine.
Something like this:
private enum State { Fire, Water, Whatever };
private State _currentState;
public void Update()
{
switch( _currentState )
{
case State.Fire:
doFireThings();
break;
case State.Water:
doWaterThings();
break;
case State.Whatever:
doWhateverThings();
break;
}
private void doFireThings()
{
// process fire
if( someConditionIsMet )
{
_state = State.Water;
}
}
private void doWaterThings()
{
// process water
if( someConditionIsMet )
{
_state = State.Fire; // change to the appropriate state
}
}
If you just want a couple of states then a simpler solution as the above is perfectly ok, but if you need more states or think that you will in the future then go for something like this to avoid your code become an if-else mess.
If you’re dead-set on doing it in Update
private bool fireCalced = false;
void Update() {
if(!fireCalced) {
fireCalced = true;
Water();
}
}
void Fire() {
fire -=1;
fireCalced = false;
}
Or, this will do it to
void Fire() {
fire -= 1;
Water();
}
void Water() {
water +=1;
}