Show different variables (health,speed,ammo..etc)
Options
Hi i have simple tank game, my tanks have different variables for exam,
Player-tank1 has 100hp and 10 speed
Player-tank2 has 300hp and 5 speed
The same values are seen when the tanks enter. tank1 = 100hp, tank2=100hp..etc
private float hp=0;
void Start()
{
hp= UnityEngine.Random.Range(100, 900);
}
How can i fix ? i need help for this. Thanks.
Player-tank1 has 100hp and 10 speed
Player-tank2 has 300hp and 5 speed
The same values are seen when the tanks enter. tank1 = 100hp, tank2=100hp..etc
private float hp=0;
void Start()
{
hp= UnityEngine.Random.Range(100, 900);
}
How can i fix ? i need help for this. Thanks.
0
Comments
-
or re-creating some hp values0
-
Can you explain better. It is not clear what problem you are facing.0
-
You should only do this:
hp= UnityEngine.Random.Range(100, 900);
for your own instance of the tank.
private float hp=0;
void Start()
{
// Only set HP for my own tank
if(photonView.IsMine)
{
hp= UnityEngine.Random.Range(100, 900);
}
}
Then at some point, when you know an opponent has entered, they can either send their HP to you through an RPC call, or sync it using serialization.0 -
Sorry for my bad english. I mean, i'm trying to give each character a different variable. I give the first character 7 speed, when another player connects, the speed is 2. as in the pictureJoey said:Can you explain better. It is not clear what problem you are facing.
It's the same code as my code, but the last connected player changes everyone's variable.Breeman said:You should only do this:
hp= UnityEngine.Random.Range(100, 900);
for your own instance of the tank.
private float hp=0;
void Start()
{
// Only set HP for my own tank
if(photonView.IsMine)
{
hp= UnityEngine.Random.Range(100, 900);
}
}
Then at some point, when you know an opponent has entered, they can either send their HP to you through an RPC call, or sync it using serialization.
*I'm using RPC only when it collides with the bullet. and target is AllBuffered0 -
If you are checking photonView.IsMine, it will only change that tank's HP and no others.0
-
can u please watch this https://www.youtube.com/watch?v=HIM7aHNPhgI whats my fault (problem) i dont understandBreeman said:If you are checking photonView.IsMine, it will only change that tank's HP and no others.
0 -
I'm not really sure. I would put some Debug.Log and see what the values are and what areas of code are being hit when a new tank is instantiated.0
-
Actually, if the health is not going to be defaulted the same between tanks, you will need to synchronize the value (RPC, etc.) at game start.
Someone else can jump in here if I'm off (I'm relatively new to Photon too!)0