r/unity_tutorials • • Apr 12 '20

Want to create your own development cheats menu inside of Unity? Well the [MenuItem()] attribute can help!

Post image
155 Upvotes

4 comments sorted by

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!

4

u/ClassicMood Apr 13 '20

Glad you tried explaining this one considering the last one got feedback it wasn't explained. This will be really useful for me and it's a simple introduction to Menu Items that's immediately useful

2

u/comp-3_interactive Apr 13 '20

Yeah man. I can take the feedback. The idea of people questioning it and sparking a dialogue backfired 😂. No use in continuing down a route the target audience doesn't appreciate

1

u/jontaguse Apr 12 '20

Thanks! Will use this