|
Post by britannis on Jan 24, 2016 22:08:20 GMT
I got the asset loading and unloading to work, but now something else bothers me. I didn’t think it would be an issue until I saw my spawn UI appear after the game is supposed to have transitioned out of the spawn objects state. Right now the game starts in a spawn state where the user clicks on white tiles and spawns an object. Once there is an object on every spawn tile, the game transitions into the select target state. I checked the Debug Inspector and the battlecontroller is not in transition. There are simply two states active (this image shows the inspector in normal mode): The transition from select spawn state to select target state takes place in a coroutine after a yield return null command. The select spawn state is based on your select target state, which is also based on your select target state. I’m curious why the select spawn state might not be disengaged after a changestate command (located in the coroutine) ?
|
|
|
Post by Admin on Jan 24, 2016 23:17:56 GMT
So there are a few assumptions here that might be misleading to you. Nothing in my StateMachine or State class modifies the "enabled" or "active" state of a MonoBehaviour. If you look over the StateMachine script you will see that it calls "Enter" and "Exit" which are custom methods defined on the State class. Any script which has implemented an "OnEnable" method will display the toggle you see in the inspector, but it has nothing to do with whether or not the state has been entered.
If you would like, you could try adding a bool field to the base state class which is set to true in the Enter method and set to false in the Exit method. This would serve as a better indicator of which state is considered "Current" by the StateMachine.
|
|
|
Post by britannis on Jan 26, 2016 11:08:26 GMT
I see. Turns out the Select Spawn State is not actually active, but the OnTileClick function in it was still being called when a tile is clicked because the script was still active. I wrapped the entire function in an if-statement, but is there a way to make it more elegant so nothing in the Select Spawn State script fires unless it is the current state?
|
|
|
Post by Admin on Jan 29, 2016 20:37:35 GMT
There are a few things you can do. In the Tactics RPG project I handled this problem by registering for input events when a state enters and unregistering for the events when a state exits. In this way I never had to worry about inactive states responding to an event.
If you tied a button click from the inspector to your state script, you won't be able to disconnect and reconnect. One way I get around this problem is I have the button click event go to a script on the same object as itself, and then have that other script post a notification and include itself as the sender. This way you can know what button is the sender of the event. Or in your case which tile was the sender of the event. Plus you can then have the ability to register and unregister for the notification as your state enters and exits.
|
|