-1

I'm new to unity and unet. I'm trying to make a cricket game. I want to share a boolean variable between two clients.

if(isBatting==null){


    if (random.Next (0, 2) == 1) {

        isBatting = true;
        Instantiate(batsmanPrefab, batsmanPrefab.transform.position, batsmanPrefab.transform.rotation);

    }else {

        isBatting = false;
        Instantiate(bowlerPrefab, bowlerPrefab.transform.position, bowlerPrefab.transform.rotation);

    }

}else{

    if(isBatting){

        Instantiate(bowlerPrefab, bowlerPrefab.transform.position, bowlerPrefab.transform.rotation);

    }else{

        Instantiate(batsmanPrefab, batsmanPrefab.transform.position, batsmanPrefab.transform.rotation);

    }

}

in the above code, when the first person joins the network, the code will randomly assign it to batting and bowling mode. Then when another joins, he will get the current state from that boolean and get its opposite mode. But i am completely beginner in unity. So i have no idea, how to send and get data from the network server.

need help...

derHugo
  • 83,094
  • 9
  • 75
  • 115
Bucky
  • 1,116
  • 2
  • 18
  • 34

1 Answers1

-1

One of the way, by using Command and RPC special methods.

  1. Command Function runs on server : You first send your desired data on server
  2. Then, Use RPC function to send data to connected client (inform connected clients).

As you are newbie I will recommend you to learn UNET first. Here, are some useful links

  1. UNet Concepts
  2. GTGD Tut
  3. Unet Actions
  4. Netwrok Manager

give sometime in learnig follow at least on tut and docs.

Muhammad Faizan Khan
  • 10,013
  • 18
  • 97
  • 186