So my objects aren't updating while pun runs

I have been making a airplane 2d shooter and when I run it the players work but no matter what when I shoot the bullets it doesn't show up on the other players screen or the enemy dying doesn't show up either.


if you are wondering the code here it is


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;

public class ProjectileBehavoir : MonoBehaviourPunCallbacks
{
  public float bulletspeed = 4.5f;
  PhotonView bulletview;

  // Start is called before the first frame update
  void Start()
  {
    bulletview = GetComponent<PhotonView>();
  }

  // Update is called once per frame
  void Update()
  {
    transform.position += transform.right * Time.deltaTime * bulletspeed;
  }

  private void OnCollisionEnter2D(Collision2D collision)
  {
    Destroy(gameObject);
  }
}


Best Answer

  • Tobias
    Tobias admin
    edited October 2022 Answer ✓

    MonoBehaviourPunCallbacks already provides a photonView. Make use of that...

    Bullets are often short lived. It might make sense to not use a PhotonView for them.

    The PUN Basics Tutorial has a shooting implementation and the Asteroids Demo has one, too. Check those out for working solutions and then modify them as needed.

    Edit: Please use the formatting options on the left hand side of the input area. You can format code and it makes it much much easier to read.

Answers

  • Tobias
    Tobias admin
    edited October 2022 Answer ✓

    MonoBehaviourPunCallbacks already provides a photonView. Make use of that...

    Bullets are often short lived. It might make sense to not use a PhotonView for them.

    The PUN Basics Tutorial has a shooting implementation and the Asteroids Demo has one, too. Check those out for working solutions and then modify them as needed.

    Edit: Please use the formatting options on the left hand side of the input area. You can format code and it makes it much much easier to read.