Question by
zoelee · Jul 10, 2017 at 06:37 PM ·
uinetworkingtext
client text not getting updated
I have a script here:
if (Input.GetKeyDown(KeyCode.Space))
{
CmdBasicAttack();
}
...
[Command]
void CmdBasicAttack()
{
if(energy >= 2){
takeEnergy(2);
energyText.text = "Energy: " + energy.ToString();
Debug.Log("energy changed" + energy.ToString());
// Create the Bullet from the Bullet Prefab
var bullet = (GameObject)Instantiate(
bulletPrefab,
bulletSpawn.position,
bulletSpawn.rotation);
// Add velocity to the bullet
bullet.GetComponent<Rigidbody2D>().velocity = bullet.transform.right * 6;
NetworkServer.Spawn(bullet);
Debug.Log("bullet Spawned");
// Destroy the bullet after 2 seconds
Destroy(bullet, 2.0f);
}else{
energyText.text = "Not Enough Energy!";
}
}
It works perfectly on the host. However it does not work on the client. I am pretty sure that the energy
variable is getting updated because after I run the function 5-6 times it stops spawning bullets. I am wondering what I am doing wrong here, what I want to have happen is that the text is updated a long with the energy variable so the player can see how much energy they have left.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612125931im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Score UI per player 1 Answer
How to keep text sharp with a scaled UI ? 0 Answers
Toggle UI Text With UI Toggle Button 1 Answer
Scroll View with text 3 Answers
UI text wont highlight 0 Answers