я делаю так.(у тебя заместо пули стрела)
создаю пулю в скрипте поведения игрока
PhotonNetwork.Instantiate(Resources.Load("Bullet").name, transform.position - transform.up * 1.6f, transform.rotation, 0);
Вешаю два скрипта на префаб пули. первый скрипт передача по сети полета пули
Используется csharp
using UnityEngine;
public class NetworkBullet : Photon.MonoBehaviour
{
void Start()
{
correctPlayerPos = transform.position;
correctPlayerRot = transform.rotation;
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
stream.SendNext(GetComponent<Rigidbody2D>().velocity);
}
else
{
correctPlayerPos = (Vector3)stream.ReceiveNext();
correctPlayerRot = (Quaternion)stream.ReceiveNext();
GetComponent<Rigidbody2D>().velocity = (Vector2)stream.ReceiveNext();
}
}
private Vector3 correctPlayerPos;
private Quaternion correctPlayerRot;
void Update()
{
if (!photonView.isMine)
{
transform.position = Vector3.Lerp(transform.position, correctPlayerPos, Time.deltaTime * 5f);
transform.rotation = Quaternion.Lerp(transform.rotation, correctPlayerRot, Time.deltaTime * 5f);
}
}
}
второй скрипт это ее поведение. например так
Используется csharp
using UnityEngine;
using System.Collections;
public class Bullet : Photon.MonoBehaviour
{
public float speed_bullet;
private Rigidbody2D rb;
void Awake()
{
if (photonView.isMine)
{
rb = GetComponent<Rigidbody2D>();
rb.velocity = -transform.up.normalized * speed_bullet;
}
}
void OnCollisionEnter2D(Collision2D other)
{
if (!photonView.isMine) return;
PhotonView target = other.gameObject.GetComponent<PhotonView>();
if (other.gameObject.tag == "Player" && !target.isMine && target.owner.customProperties["Immortal"].ToString() == "False")
{// второе условие чтобы не убивать себя своей пулей
other.gameObject.GetComponent<PhotonView>().RPC("destroy_player", PhotonTargets.All);
}
StartCoroutine(bullet_self_destruct_());
}
IEnumerator bullet_self_destruct_()
{ /// звук пули чтобы не обрывался когда стреляем впритык.
GetComponent<SpriteRenderer>().enabled = false;
GetComponent<BoxCollider2D>().enabled = false;
while (GetComponent<AudioSource>().isPlaying == true)
yield return new WaitForSeconds(0.1f);
PhotonNetwork.Destroy(gameObject);
}
}