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.

Comments

  • Duran
    Options
    or re-creating some hp values
  • Joey
    Options
    Can you explain better. It is not clear what problem you are facing.
  • Breeman
    Options
    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.
  • Duran
    Options
    Joey said:

    Can you explain better. It is not clear what problem you are facing.

    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 picture


    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.

    It's the same code as my code, but the last connected player changes everyone's variable.
    *I'm using RPC only when it collides with the bullet. and target is AllBuffered
  • Breeman
    Options
    If you are checking photonView.IsMine, it will only change that tank's HP and no others.
  • Duran
    Options
    Breeman said:

    If you are checking photonView.IsMine, it will only change that tank's HP and no others.

    can u please watch this https://www.youtube.com/watch?v=HIM7aHNPhgI whats my fault (problem) i dont understand
  • Breeman
    Options
    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.
  • Breeman
    Breeman
    edited March 2019
    Options
    @Duran

    public float hiz=2;

    This will set hiz=2 no matter what IsMine is set to.
  • Duran
    Options
    Breeman said:

    @Duran

    public float hiz=2;

    This will set hiz=2 no matter what IsMine is set to.

    How should I define this variable? private ? or null ?
  • Breeman
    Breeman
    edited March 2019
    Options
    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!)