Obstacles don't appear the same to all players!!

Xeyo
Xeyo

I made a script where it will spawn a random object, script example below:


but when a player gets a pipe the other player gets a different object for this example a BAT.


How can i make where the players see the same objects that spawn???

 public GameObject Pipe;
  public GameObject Bat;

  float timer;
  public float maxTime;

  public float minY, maxY;
  // Update is called once per frame

  void Start()
  {
    Spawn();
  }

  void Update()
  {
    timer += Time.deltaTime;
    if (timer >= maxTime)
    {
      Spawn();
      timer = 0;

    }
  }

  void Spawn()
  {
      float randomNumber = Random.Range(1, 7);

      if (randomNumber == 1)
      {
        maxTime = 2;

        float randYPos = Random.Range(minY, maxY);


        GameObject newpipe = Instantiate(Pipe);
        newpipe.transform.position = new Vector2(
          transform.position.x,
          randYPos);

        //speedd += 0.6f * Time.deltaTime;

      }

      if (randomNumber == 2)
      {
        maxTime = 2;

        float randYPos = Random.Range(minY, maxY);


        GameObject newpipe = Instantiate(Bat);
        newpipe.transform.position = new Vector2(
          transform.position.x,
          randYPos);

        //speedd += 0.6f * Time.deltaTime;

      }
  }

Answers

  • I would recommend to read and code-along the PUN Basics Tutorial.

    It shows PhotonNetwork.Instantiate, which is the networked version of what you want to do.

    If you want to just synchronize what needs to be instantiated (and you want every client to instantiate the same object but not as a networked one), you have to decide if you want to use Custom Properties, RaiseEvent or an RPC for that. The Synchronizing State doc should help.