My goal with this project was to make systems that would allow a designer to create a point-and-click game without having to write any code. In order to achieve this I wanted to test out Unity's visual scripting system. I was led to believe the state machines in this system worked like PlayMaker, which I had used previously. This turned out to not be completely true, but I managed to get it to do somewhat what I wanted anyway.
I used visual scripting to make a simple dialogue system. This process was made pretty easy due to the visual scripting system being able to use any function as a node, and so I only had to write the component code and it was ready to go. In order to make it even easier to use I also made all the functions intended to be used in visual scripting static, so you don't have to specify a component instance when adding a node.
public static void Say(string text, string name) { dialogue.background.enabled = true; dialogue.box.enabled = true; dialogue.text.enabled = true; dialogue.text.text = text.Replace("<br>", "\n"); if (!string.IsNullOrEmpty(name)) { dialogue.nameBox.enabled = true; dialogue.nameText.enabled = true; dialogue.nameText.text = name; } else { dialogue.nameBox.enabled = false; dialogue.nameText.enabled = false; } }
For items I used scriptable objects, which is basically a custom asset type that can contain some data and be created from Unity's asset menu.
[CreateAssetMenu] public class Item : ScriptableObject { public string description; public Sprite image; public Item combineWith; public Item combineResult; }
Items can then be added, removed, and checked in visual scripting. This is useful for things like characters giving the player something, the player giving characters something, and branching dialogue based on what items the player does or doesn't have. I also made a component for picking up items directly, so you don't have to create a whole interaction for getting just one item.
public static void AddItem(Item item) { for (int index = 0; index < inventorySlots.Length; index++) { if (!inventorySlots[index].HasItem()) { inventorySlots[index].SetItem(item); return; } } Debug.LogError("Cannot add item " + item.name + " due to inventory being full"); }
Items are stored in inventory slots, the amount of which can be set with just an integer in the editor. Inventory slots also handle items being dragged onto (and possibly combined with) other items in the inventory, or characters or objects in the game world.
public void Drop() { if (!item || !draggedItem) { draggedItem = null; return; } if (item.combineWith == draggedItem || draggedItem.combineWith == item) { Item result; if (item.combineResult) { result = item.combineResult; } else { result = draggedItem.combineResult; } Player.RemoveItem(item); Player.RemoveItem(draggedItem); Player.AddItem(result); } draggedItem = null; }
Putting all of this together I was able to make a game without having anything specific to it be hard coded. Everything is created in the editor, and all interactions are made with visual scripting.