Simple RPG
This scene contains an example of a simple RPG experience where you can level up, change class, and defeat enemies.
Using the Example
Open the scene or visit the example world in VRChat using the persistence-beta
branch.
- Open the scene RPGExample in the Assets/Examples/RPG folder.
- Play the scene.
- Choose a class by walking over the corresponding pedestal.
- Once you've gained enough experience by killing enemies, you will level up. You can tell your level by the amount of diamonds above your head.
- Rejoin the world.
- When you load into the world, you should be teleported to your previous position and have your last selected class with the same level and experience.
Importing the Example
Follow the steps below to add this example to your Unity project:
- Open the Example Central Window from the window from the Unity Editor Menu under "VRChat SDK > 🏠 Example Central"
- Find this prefab in the list or search for it by title (same as the title of this page).
- Press the "Import" button to import the Unitypackage into your project.
Technical Breakdown
RPGPlayer is a script attached to a GameObject, which has the PlayerObject script on it, this means that the RPGPlayer script is instantiated once for each player. RPGPlayer is what controls so you can see the diamonds above a players head indicating their class and level, this also is what makes it so you can see others weapon.
Then there are 3 different pedestals you can walk over, which, when triggered, will tell your own RPGPlayer instance to change its class.
The class, last position, experience, and level are all persistent by being UdonSynced and being on a VRCPlayerObject. Any UdonSynced variables that are on a script that is on a GameObject that is part of a PlayerObject are automatically persistent.
Combat is done using particle collisions, so each class has a different type of particle effect as an attack, which has a collider on it. The enemies give 1 exp when killed, and you need 4 exp for leveling up. Enemies respawn 10–15 seconds after being killed.
Changelog
- 0.0.3: Added Instructions Canvas
- 0.0.2: Script tweaks: RPG Example uses
VRCEnablePersistence
components on player objects so that they persist again