[PunRPC]
private void OnTriggerEnter2D(Collider2D other)
{
if (view.IsMine)
{
if (other.CompareTag("Weapon"))
{
for (int i = 0; i < allWeapons.Length; i++)
{
if (other.name == allWeapons[i].name)
{
unlockWeapons.Add(allWeapons[i]);
}
}
PhotonView playerView = PhotonView.Get(this);
playerView.RPC("SwitchWeapon", RpcTarget.AllBufferedViaServer); // конкретный участок использования RPC
PhotonNetwork.Destroy(other.gameObject);
}
if (other.CompareTag("Bullet"))
{
health -= 10;
}
if (other.CompareTag("Heal"))
{
health += 10;
PhotonNetwork.Destroy(other.gameObject);
}
}
}
[PunRPC]
public void SwitchWeapon()
{
for (int i = 0; i < unlockWeapons.Count; i++)
{
if (unlockWeapons[i].activeInHierarchy)
{
unlockWeapons[i].SetActive(false);
GameObject currentWepaon = unlockWeapons[i != 0 ? i - 1 : unlockWeapons.Count - 1];
currentWepaon.SetActive(true);
weaponIcon.sprite = currentWepaon.GetComponent<SpriteRenderer>().sprite;
weaponIcon.SetNativeSize();
break;
}
}
}
*Метод OnTriggerEnter можно и не обозначать как [PunRPC].
[PunRPC]
public void SwitchWeapon()
{
for (int i = 0; i < unlockWeapons.Count; i++)
{
if (unlockWeapons[i].activeInHierarchy)
{
unlockWeapons[i].SetActive(false);
GameObject currentWepaon = unlockWeapons[i != 0 ? i - 1 : unlockWeapons.Count - 1];
currentWepaon.SetActive(true);
weaponIcon.sprite = currentWepaon.GetComponent<SpriteRenderer>().sprite;
weaponIcon.SetNativeSize();
break;
}
}
}