Blender to Unity and Playmaker | Part 4: Adding interaction


For those of you who don’t know what playmaker
is. Playmaker is an extension to Unity editor
created by a company called Hutong. Playmaker basically adds FSM or finite state
machine functionality to game object in Unity. I will not cover the detail too much in this
tutorial about what is FSM and how to use Playmaker from scratch, because you can find
very clear and complete tutorials about playmaker FSM in Hutong’s website. Okay so to add a new FSM open the playmaker
editor and just right click and then choose “add FSM”. Notice by doing this a playmaker component
is added to the object. So if later, you want to remove the FSM, simply
click this option panel and choose remove component. Okay. Now, the first state or the state that has
the start event on it, we want to rename this state to “closed”. Because at first the chest should be in closed
condition. And then right click add another state and
name it “opening”. Then another state called “opened”. And the last state will be “closing” state. Okay, now that our states are all defined. We need to create an event. Event in programming terms are something that
is happening and that we want to inform other object or objects about it. In Playmaker, an event is symbolized as arrows. So basically if you want to create an arrow
or transition then you need to create an event. Okay. So in the event tab we can create a new event
by typing “Clicked” and then just hit enter. You can name event to any name you want as
long as it make sense to you and so you or your team will understand it. We name our event “clicked” for any transition
between state that happens due to user’s mouse click. So to use the event, we can right click on
the closed state and then “add transition” notice the clicked event that we create before
is nicely listed in here by playmaker. Drag this event so it creates an arrow to
the opening state. In the opening state we’re going to play
the opening animation. Then after it is finished, it should automatically
transitioning to the opened state. Now for finish event, we actually don’t need
to create it our self as playmaker already has one called “FINISHED” with all capital
letter. Next from “opened” state to “closing”
state we can use the clicked event again. And from “closing” animation state to
“closed” state we can use finished event like before. So again. When the game start the object will be in
closed state. Then when the user click the object, it should
go to the opening state which plays the animation. Then after the animation finished playing,
it will jump to the opened state. Then when in opened state, the user click
on it, it will go to the closing animation state. And after the animation is finished it will
go back to the closed state. Okay. Currently our FSM will do nothing as we don’t
have any actions inside each of the state. To add an action. Lest pick the “closed” state first. Then in the state tab, down here we can see
the “action browser” button. Click it and then type “pick”. You will see “mouse pick event” action
listed. We can double click on it. Now, the mouse pick event action is added
to the “closed” state. The “game object” option up here determine
which object will be the target. “Use owner” means that it will target
it self to check whether it is being clicked or not. Now this is possible because we have a collider
component up here. If no collider exist in this object, playmaker
will display red error message. Okay, now “mouse pick event” action can
actually pick a lot of mouse events. Not just mouse clicking event. But right now we’re only interested in clicking
event. For clicking we can actually use “mouse
down” or “mouse up” events. Lets choose “mouse down” event for now. Click on this pull down list and choose “clicked”
which is the name of our existing event. So basically when the mouse is down on this
object then the “clicked” event will fire off and it will transition the FSM to the
next state which is the opening state. In the opening state, we want to have play
animation action. So click on the action browser and then type
“play”. Double click on this “play animation”
action. Okay. The “game object” is the target object
just as we mentioned before. We can use “specify game object” if we
want to play the animation on other object. “Use owner” means the object who owns
the playmaker FSM, which is this object it self. Okay now on the “anim name” option, if
we click on this list we can see playmaker cleverly list all the available animations
that this object has. Choose “opening” now. Okay. Now lets test it. Click the play game button up here. Sorry we need to turn off this “maximize
on play” toggle button up here, so we can see the playmaker editor while the game is
running. Lets hit play again. Now as we can see as soon as the game play,
the closed state will become active. And currently it is waiting for the mouse
key down event. If we click on it. It will fire up the “clicked” event and
move the FSM to the “opening” state where the opening animation take place. After finish playing the animation it will
automatically transitioned to the opened state. From this “opened” state we can not go
any further as we haven’t create any actions for it. But the process is similar. So lets turn off play for now. Pick this state then click in here to select
the action. Press control C to copy. Then pick this state. Click in here and then control V to paste
the action. Okay, now of course for this state, it should
play the “closing” animation. Next, lets pick this state, click in here
and press control C. Then click this state. Click in here and paste it in. For this action we actually don’t need to
change anything. Okay so that’s it. Lets do a final test. Lets make it maximize for now. Hit play again. Click to open. And then click to close. Okay guys, as always don’t forget to subscribe
to my channel. Give a thumbs-up if you like the video and
give a thumbs-down if you don’t like the video. See you in my other tutorials. Wassalamualaikum.

Leave a Reply

Your email address will not be published. Required fields are marked *