Download as pdf or txt
Download as pdf or txt
You are on page 1of 40

Unity3D and Fungus

Options
Add Option Blocks

Open your flowchart and add 3 new Blocks.
– Name them Option1, Option2, Option3 respectively.
– Add a Narrative/Say command to each of the 3 blocks.

Set <execute on event> to None
Add Option Menu Items

Select the original Block and add 3 Narrative/Menu.
– Name them Option1, Option2, Option3 respectively.
– Add a Narrative/Say command to each of the 3 blocks.

Set Text and Target Block respectively.
Test

Test each of the menu items.
Try This

Switch the order of commands to see the effect.
Flowchart
Variables
Add a Variable

Open your flowchart and add 1 integer variable.
– Name this variable money. And set it to Public.
Add Some Value to a Variable

Select Option1 Block. Append a Variable/Set Variable command at the end.
– We are going to a 100 to money if our Player select Option1,
– 200 money for Option2,
– 500 money for Option3.
Test

Test each of the menu items. The money variable in Flowchart
should be changed.
Unity
Variables
Add a UnityGameManger Class

For Unity beginners, most game variable can be
grouped and owned by a GameManager class.
– There should be only one GameManager instant works at a
time. Multiple GameManager instances working together
causes variable value ambiguity problems.
– Add a empty GameObject and name it GameManager,
– and create a GameManager C# class on it.
Invoke Unity Method in Fungus

Back to Flowchart, select the parent Block, and select Option1.
– Delete the Narrative/Set Variable, Add a Scripting/Invoke Method.

Target object: GameManager

Target component: GameManager

Target method: AddMoney

Parameters: 100
– Do the same modification for Option2 and Option3 with
corresponding values.
Test

Test each of the menu items. The money variable in
GameManager component should be changed.
3rd Person
Integrate with Invector 3 Person rd


Third Person Controller - Basic Locomotion FREE -by Invector
Integrate with Invector 3 Person rd


Open and play the template
– Assets\Invector-3rdPersonController_LITE\Invector_BasicLocomotion
Collision
Place Ground Plane and Prefabs

Open your Fungus test scene. Turn off the Fungus Block.

Place a Plane as ground. Reset its transform.
Place Ground Plane and Prefabs

Place Invector prefabs. Reset their transforms.
– ThirdPersonController_LITE
– vThirdPersonCamera_LITE

Delete Main Camera
Place NPC

Place and Capsule to pretend an NPC.
– Put it to a corner.
Place NPC

Add an C# custom component on NPC capsule. Name it MyNPC
– Double Click to edit its C# program

OnCollisionEnter will be fired when NPC capsule is colliding with some other GameObjects

Print some messages in console when the colliding GO is ThirdPersonController_LITE
Place NPC

Here is the corresponding visual script.
Place NPC

Test
Integration
Set The Trigger Message of Block

Open your Fungus flowchart and select your Block.
– Set <Execute on Event> to
Message Received.
– And set the <Message> name to
MyNPCEvent

When we send corresponding message to
this flowchart, this Block will be stated.
Set The Trigger Message of Block

Open your MyNPC C# program and modify your code.
Place NPC

Test
Visual Scripting for Fungus

Add Fungus to Visual Scripting
– Preference → Visual Scripting → Type Options

Add Flowchart to type options.
– Preference → Visual Scripting → Node Library

Add Fungus to node library
– Click Regenerate Nodes to generate Fungus Visual Scripting nodes.
Visual Scripting for Fungus

Add new Graph Variables
– Name: flowchart
– Type: Flowchart

Modify MyNPC_VS
Fungus
Logic
Example: State of NPC

Create an 3-state NPC.
– The states of NPC: State1, State2, State3
– Everytime when the Player talks to the NPC, the NPC changes its state to next state in
cyclically.

We plan to use one Flowchart variable: NPCState to control the
NPC.
– Create 2 variables. One is a Unity integer variable and the other one is a Fungus variable,
– Write C# functions to load C# variable to Fungus variable.

Put main logic and data in C#, and load variable to Fungus for
visual representation.



Test

Assign a NPCState value to MyNPC and test its response.
Make it Cyclic

Test
Q&A

You might also like