Unity3d playmaker Plug-in tutorial, six, blood volume display and processing

Source: Internet
Author: User

This shows how to handle and display the amount of blood, how to use global variables to pass information under multiple state machines, how to use a similar if judgment, and how to convert data types.


Prepare work, blood volume display text box



Bloody props.



Simulate player's bucket



First, create a new empty game Object, named Healthmanager, to manage the entire process



Add Setup, Updategui, addhealth, listener status.
Add the Add_health event.



Add Global variables



If you add a global variable, you cannot add and the following error occurs



Because a directory is missing, you can add a resources directory under the Assets\plugins\playmaker directory.



Add 3 global Variables

Add current_health_i storage volume, type integer

Add current_health_s to display the amount of blood, type string

Add Health_manager for delivery, type is Gameobject



Add state rotate under Health_cross, add rotate action to rotate the cross



Add a cube that determines the range.

Yesterday saw the next playmaker website, said, there is a unified father's words can be convenient to get all the son. It seems to be the meaning. Just do it.



Add the setup state and the Updatehealth state to the cube and add the Health_pick_up event. and add the trigger event action in the Setup state



Add the Get Parent action and Destory object action in the Updatehealth state, destroying itself when the player touches it.



This is to send the player a message to Healthmanager and add the Send event action



This time, the global variable Health_manager is working, set the following



At this point, you also need to set the Add_health event under Healthmanager as a global event,


Then fill in the state machine name and check the global event add_health.



The global variable Health_manager has not yet been assigned, and in the Healthmanager setup state, add the get owner action,



Run preview, when the player touches the booster, the Healthmanager state is triggered correctly.



In the setup state of Healthmanager, add action: Set Int Value, set the blood volume to 50,


In the Updategui state, add the convert Int to string action, transform the data type, and add the set GUI text action to display the amount of blood.



Add the action int add in the Addhealth state to modify the amount of blood.



Run preview, start status



Contact with the booster, state trigger, blood volume display correct



Add a blood-reducing platform, it is a fire, the monster put the trap of what is good.



Add Listener, decreasehealth status,

Add Decrease_health Event



Add trigger event action in listener state to handle incoming



As with the addition of blood, you need to add decrease_health global events under Healthmanager.



Add the Send event action on the Cube fire side,



Run preview



When entering cube, the state is triggered correctly.



This time, when the player constantly pick up the blood booster, the amount of blood will always increase, the blood volume is less than 0 can also continue.

Now to deal with this problem.

Due to the limitations of playmaker plug-in judgment function, the idea is as follows.
After adding blood or reducing blood, go to CheckHealth100 State
In this state to detect whether the blood volume is more than 100,
If more than 100, change the amount of blood in the resethealth state back to 100
If not more than 100, go to CheckHealth0 state, determine whether the blood volume is less than or equal to 100
When the amount of blood is less than or equal to 0 o'clock, the game ends.


Add an int compare action in the CHECKHEALTH100 state, the first value is the amount of blood, the second value is 100,

Equal, less than, more than triggering different actions respectively.

Feel this paragraph, write code to come simple.



When the blood volume exceeds 100, the amount of blood is changed back to 100 with the set INT value action.



When the amount of blood is less than or equal to 0, the game is over



When the game is over, simply display the text.



Run a preview when the player's blood volume is 100



And then we'll have the blood and the blood.



When the player's blood volume is less than 0, the game over is displayed.


Unity3d playmaker Plug-in tutorial, six, blood volume display and processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.