playMaker

Author Topic: Having actions and progress bars  (Read 1905 times)

Tommy Dawkins

  • Playmaker Newbie
  • *
  • Posts: 2
Having actions and progress bars
« on: December 22, 2020, 02:03:22 AM »
Hi,

Currently playing around in Unity 2D and I have an image that I want, when clicked, to start a mining action. This mining action will take 5 seconds (but may decrease in time as upgrades are purchased) and will start when the image is clicked. With the mining action having less time with upgrades.


1. How do I create/record the value (number of ores) that the player has? Where would I create the initial variable to store this data so that it could ultimately be added to by the FSM and at the same time update the Text UI component.

2. How do I have the FSM update the progress bar that I am using? or how would I go about having this factored in.
« Last Edit: December 22, 2020, 03:27:11 AM by Tommy Dawkins »

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Having actions and progress bars
« Reply #1 on: December 22, 2020, 09:34:49 AM »
You need to start with some basic tutorials. Have you done the tutorials listed on this website?

You'll find plenty of info regarding setting variables, and creating UI bars, UI Set Fill etc.

Tommy Dawkins

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Having actions and progress bars
« Reply #2 on: December 23, 2020, 12:37:14 AM »
I've had a look at some but it is hard to extrapolate from "light on/off" sort of demos, so hoping to be pointed towards more specific tutorials that cover the set and get of variables from FSM to the UI.

Dumb Game Dev covered some stuff but nothing that actually helped beyond the basics.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Having actions and progress bars
« Reply #3 on: December 23, 2020, 05:54:49 AM »
Hi.
Maybe some of my videos can help :
https://www.youtube.com/c/JinxterGames/featured

LuminRabbit

  • Full Member
  • ***
  • Posts: 161
  • Lumin Rabbit
Re: Having actions and progress bars
« Reply #4 on: December 26, 2020, 08:49:30 PM »
You can start off by creating a UI Slider this could be your bar (you can remove the knob but do it later so you can see how it works), also note it has a "value" in the inspector you can use this to see how many ores you have, set max value to 100 and set value to 100.

Create an empty game object name it what you want and use this to put your FSM on. Also create a button (easier than an image).

Now the Magic:
Drag and drop the slider onto the first state, Choose slider/set property, in the property field drop down select value. if you hit play you'll notice the slider goes from 100 to 0, yay this is where you can change the amount of ores. Click "set value" hamburger menu now it will say none for the set value, click on none drop down select new variable and name it ore. On the variables tab select ore and give it a value of 100. Then go back to the state tab.

Name your button text Ore.

Lets get back to your FSM and in the first state lets add another action Float Subtract, select the float variable ore, then lets put in 10 for subtract, check everyframe for the set property and for the float subtract and also select per second. Now hit play ;)

Right click in your FSM create a new state then right click on this state and select "set as start state"

Click on the Events tab, at the bottom type in Make then hit enter. you'll see the new event now created click the checkbox next to it so that its global. Click ok for the box that pops up. Right click on the state that has the float subtract, right click add a global transition then select Make.

Last but not least go to your button, in the hierarchy "On Click()" click the plus button, drag the object that has your FSM into this spot, click on the no function drop down and select "PlaymakerFSM>SendEvent(string)" now type in Maker.

Go back to the gameobject that has your FSM click it then hit Play, in the game scene click on your ore button and watch the magic!

you caould add another state and in the Make state and do a float compare for when it hits zero to do something else, you could also use int's instead of floats.

anyway this should get you started...


 
Have I said how much I love playmaker!!! This is one amazing tool