I've added some text to a unity UI and set both the achor and pivot to the top right corner as shown here:
When I start this in debug in unity the text looks fine:
What's weird is that when I build the app and run it as an executable as a host (this is a multiplayer networked game) the text also looks fine. But when I start a client instance the text doesn't appear.
I debugged and paused the game in unity in client mode and noticed that the text object is miles away from where I'm expecting it to be (and as a result doesn't show on the camera).
You can just about see the black line on the below image which is my level and the text anchored miles up and right of the level.
It seems like I've done something stupid here but I can't work out what :s
EDIT: Leo's answer was correct conceptually, but here's how I implemented the suggestion.
- Created an empty game object
GameStateManagerin the hierarchy
- Add a
GameStatescript to the manager with a network identity
- Added my 'RemainingTime' property to the game state script and put the [SyncVar] attribute on it
- Put logic in the game state
Updatemethod to update the remaining time
- Added a
ClientTimerscript to the text object (mono behaviour), which retrieved the
GameStatefrom within the clients copy of the game state manager.
- In the update method of the client time, get a reference to the
Textobject and set the
.textproperty to the value of the remaining time.
I'm not sure if this is correct, but it does seem to work, and now the
ClientTimer script isn't networked, which resolved the issues with placement of the text.