A client script will update the UI based on the progress of the nav mesh. When the nav mesh has been generated, the client script will handle hiding the UI for the player so they can then play the game.
Create PlayerClient Script
Create a new script called PlayerClient and place it in the Client Scripts folder in the Hierarchy.
Add Custom Properties
The client script will need custom properties so it can read the dynamic properties, update the progress text, and hide the container.
Add the UI Container as a custom property, and name it UIContainer.
Add the Generated Map folder as a custom property, and name it GeneratedMap.
Add the Progress text component as a custom property, and name it Progress.
Edit PlayerClient Script
Open up the PlayerClient script so you can edit it and create the code.
Add Variables
Add the following variables to the script so you have references to the custom properties you added.
local UI_CONTAINER = script:GetCustomProperty("UIContainer"):WaitForObject()
local GENERATED_MAP = script:GetCustomProperty("GeneratedMap"):WaitForObject()
local PROGRESS = script:GetCustomProperty("Progress"):WaitForObject()Code language:Lua(lua)
Create HideUI Function
Create a function called HideUI that will turn the visibility of the UI Container off.
Create a function called UpdateProgress. This function will be responsible for updating the progress text. It will get called when the dynamic custom properties change.
Because there are 2 properties, the first one for the grid needs to be divided by 2 so it contributes 50% to the progress. When the mesh is in progress, you can divide the val by 2 and add 50 to give you the total progress between 0 and 100%.
localfunctionUpdateProgress(obj, prop)if prop == "grid"thenlocal val = GENERATED_MAP:GetCustomProperty("grid")
if val > 0then
PROGRESS.text = string.format("%.2f%%", (GENERATED_MAP:GetCustomProperty("grid") / 2) * 100)
endelseif prop == "mesh"thenlocal val = GENERATED_MAP:GetCustomProperty("mesh")
if val > 0then
PROGRESS.text = string.format("%.2f%%", 50 + (val / 2) * 100)
endendendCode language:Lua(lua)
Connect Property Changed Event
When the dynamic custom property value changes, it will fire the customPropertyChangedEvent. By connecting a function to this event, you can listen to those changes to update the progress text.
2 calls to the UpdateProgress function for the grid and mesh are recommended to do in case the changed event has not connected. This could be because the player joined later and the nav mesh has been generated.
This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
Strictly Necessary Cookies
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.
3rd Party Cookies
This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.
Keeping this cookie enabled helps us to improve our website.
Please enable Strictly Necessary Cookies first so that we can save your preferences!