A Unity 3D demo where a third-person character picks up a sphere and that pickup sends a POST request to a mock JSON API.
When the scene starts, player stats (name, health, personality, charm, behavior, management) are loaded from a mock REST endpoint and shown in a HUD. Walk the character into the sphere: it disappears, the Intellect stat on screen jumps to 3, and a POST request sends a new Health value to the server, whose reply is shown in the Health text.
It reuses the GET and POST scripts from unity-json-get-post, and the data comes from the db.json in unity-mock-player-data.
- ThirdPersonBehaviour.cs (in
Assets/Invector-3rdPersonController_LITE/Scripts/CharacterController/) sits on the player. InOnTriggerEnterit checks for theBalltag, finds theServerUpdateGameObject, callsPostMethod.PostData(), destroys the ball, setsintallectto 3 and updates a TextMeshPro label. It also exposesethics,honestyandkindnesssliders (1 to 3) that are not used yet. - Assets/Script/PostMethod.cs builds a
WWWFormwithHealth=110, sends it withUnityWebRequest.Post, showsLoading..., and writes the returnedHealthinto a UIText. HerePostData()is public and only runs when called. - Assets/Script/Demo.cs runs a GET in
Start, parses the JSON into aDatastruct withJsonUtility, and fills six UITextfields. The image download from the GET-POST demo is commented out. - Character movement and camera come from the Invector Third Person Controller LITE asset included in
Assets/.
- Unity 2020.3.25f1
- UGUI 1.0.0, TextMeshPro 3.0.6, Timeline 1.4.8
- Invector Third Person Controller LITE (Asset Store package, committed in
Assets/) UnityWebRequest,JsonUtility
- Clone the repo and open it in Unity Hub with Unity 2020.3.25f1.
- Open
Assets/Invector-3rdPersonController_LITE/Invector_BasicLocomotion.unity(notAssets/Scenes/SampleScene.unity, which has none of the demo set up) and press Play. - Move with WASD and walk into the sphere to trigger the POST.
- To build your own version: tag the pickup
Ballwith a trigger collider, putPostMethodon a GameObject named exactlyServerUpdate, addThirdPersonBehaviourto the player and assign itsIntellect_txt, and assign the UITextfields onDemoandPostMethod.
| Script | Purpose |
|---|---|
Assets/Script/Demo.cs |
GET request that fills the stats HUD |
Assets/Script/PostMethod.cs |
POST request that sends a new Health value |
Assets/Invector-3rdPersonController_LITE/Scripts/CharacterController/ThirdPersonBehaviour.cs |
Detects the Ball pickup and triggers the POST |
- Despite the repository name, the character is third person, not first person.
Library/andTemp/were committed (about 8,000 generated files, roughly 115 MB of history). Unity regenerates them; they should be removed from the repo and added to a.gitignore. Some paths inLibrary/PackageCacheare long enough to fail checkout on Windows unlessgit config core.longpaths trueis set.- The endpoint
https://my-json-server.typicode.com/MemeGamer/MockData/UnityDatastill uses the old repo nameMockData; the repo is nowunity-mock-player-data. At the time of writing, My JSON Server returned errors for both names. It is also a fake REST API, so POSTs are not saved. - The Invector LITE asset and its 17 MB trailer video are third-party Asset Store content redistributed in this repo.
isNetworkErrorandisHttpErrorare deprecated in Unity 2020.2 and later and produce warnings.
