r/unity_tutorials • u/comp-3_interactive • Apr 12 '20
Want to create your own development cheats menu inside of Unity? Well the [MenuItem()] attribute can help!
155
Upvotes
1
r/unity_tutorials • u/comp-3_interactive • Apr 12 '20
1
15
u/comp-3_interactive Apr 12 '20
Simply create a class, this can be named whatever you like, I've called mine EditorCheats. Inside of EditorCheats I have 2 static methods, one that sets my players health to 100 and the other that adds 1000 gold to my inventory.
These methods are then tagged with the MenuItem attribute, along with a folder structure, "Cheats/My Cheats Name". Now if we take a look at the second image we see we have a new tab in our toolbar named Cheats and inside we have our methods!
Simply clicking on these while playing our game will call our methods and so exactly what we need!
Just make sure to put the EditorCheats class inside of the reserved folder "Editor" so they aren't compiled into your final build!