when I connect via the network. my character launches a rocket and the character who connects does not see how I fire a rocket

This script is tied to the character.

public GameObject Rocket; //ракеты спаунятся только у мастера if (photonView.isMine) { //вызываем объект ракету и придаем ей силу Instantiate(Rocket, transform.position + transform.forward * 2, transform.rotation); } 

This script is tied to a rocket.

 public int power; void Start () { gameObject.GetComponent<Rigidbody>().AddForce(transform.forward * power); } 

Closed due to the fact that off-topic participants Andrew , aleksandr barakin , LFC , Enikeyschik , yolosora Feb 5 at 2:08 pm .

  • Most likely, this question does not correspond to the subject of Stack Overflow in Russian, according to the rules described in the certificate .
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • since photon is used (is it used?) then you need to look for information about events in the documentation of the photon itself ( doc.photonengine.com/en-us/bolt/current/reference/events ). And the more you need to specify which library you are going to use for this, if you are going to. This makes it possible that they will answer you here at least somehow. - Andrew
  • 3
    This question should be closed, because there is not enough information to answer objectively. - Andrew

1 answer 1

It is better to really indicate that you are using Photon - and then you have to guess from the code itself, where you have the PhotonView.IsMine property

To make the Instantiate method networked is quite simple - in the script that is tied to the character, we replace the Instantiate(Объект для спауна, позиция, поворот) на сетевое method Instantiate(Объект для спауна, позиция, поворот) на сетевое PhotonNetwork.Instantiate("Имя объекта для спауна", позиция, поворот, группа (=0))

The object with the name for the spawn should be in the Assets/Resources folder, and the PhotonView component should be hung on it. Then everything will turn out and the object will appear in all players in the room.

The final code for the character (the rocket does not need to change anything, only PhotonView and shove the prefab into the resources)

 //ракеты спаунятся только у мастера if (photonView.isMine) { //вызываем объект ракету и придаем ей силу PhotonNetwork.Instantiate("Rocket", transform.position + transform.forward * 2, transform.rotation,0); }