no suitable method found to override even though everything is correct
Hello I am using photon 2 pun for unity and I was following a tutorial but something went wrong.
I copied the code exactly, however I still get that error to the line that I am overriding.
using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Hastable = ExitGames.Client.Photon.Hashtable;
using Photon.Realtime;
public class WeaponSwitcher : MonoBehaviourPunCallbacks
{
public int selectedWeapon = 0;
public PhotonView view;
void Start()
{
SelectWeapon();
}
void Update()
{
if (view.IsMine)
{
int previousSelectedWeapon = selectedWeapon;
if (Input.GetAxis("Mouse ScrollWheel") > 0f)
{
if (selectedWeapon >= transform.childCount - 1)
{
selectedWeapon = 0;
}
else
{
selectedWeapon++;
}
}
if (Input.GetAxis("Mouse ScrollWheel") < 0f)
{
if (selectedWeapon <= 0)
{
selectedWeapon = transform.childCount - 1;
}
else
{
selectedWeapon--;
}
}
if (previousSelectedWeapon != selectedWeapon)
{
SelectWeapon();
}
}
}
void SelectWeapon()
{
int i = 0;
foreach (Transform weapon in transform)
{
if (i == selectedWeapon)
{
weapon.gameObject.SetActive(true);
}
else
{
weapon.gameObject.SetActive(false);
}
i++;
}
if (view.IsMine)
{
Hashtable hash = new Hashtable();
hash.Add("selectedWeapon", selectedWeapon);
PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
}
}
public override void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps) //line of error
{
if (!view.IsMine && targetPlayer == view.Owner)
{
SelectWeapon((int)changedProps["selectedWeapon"]);
}
}
}
sorry if it is messy I don't know how to post code.
What is wrong?
Best Answer
-
dont worry i managed to find a solution.
dont know how or why but it works now.
i will post script.
using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Realtime;
using Hashtable = ExitGames.Client.Photon.Hashtable;
public class WeaponSwitcher : MonoBehaviourPunCallbacks
{
[SerializeField] GameObject[] items;
int itemIndex;
int previousItemIndex = -1;
[SerializeField] PhotonView view;
void Start()
{
if (view.IsMine)
{
EquipItem(0);
}
else
{
}
}
void Update()
{
for (int i = 0; i < items.Length; i++)
{
if (Input.GetKeyDown((i + 1).ToString()))
{
EquipItem(i);
break;
}
}
if (view.IsMine)
{
if (Input.GetAxisRaw("Mouse ScrollWheel") > 0f)
{
if (itemIndex >= items.Length - 1)
{
EquipItem(0);
}
else
{
EquipItem(itemIndex + 1);
}
}
else if (Input.GetAxisRaw("Mouse ScrollWheel") < 0f)
{
if (itemIndex <= 0)
{
EquipItem(items.Length - 1);
}
else
{
EquipItem(itemIndex - 1);
}
}
}
}
void EquipItem(int _index)
{
if (_index == previousItemIndex)
{
return;
}
itemIndex = _index;
items[itemIndex].SetActive(true);
if (previousItemIndex != -1)
{
items[previousItemIndex].SetActive(false);
}
previousItemIndex = itemIndex;
if (view.IsMine)
{
Hashtable hash = new Hashtable();
hash.Add("itemIndex", itemIndex);
PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
}
}
public override void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps)
{
if (!view.IsMine && targetPlayer == view.Owner)
{
EquipItem((int)changedProps["itemIndex"]);
}
}
}
0
Answers
-
Theres nothing wrong in that line, are you sure your still getting the error in that line, that script? Please post your whole error message!
0 -
Yes I am still getting it.
The full error is :
Assets\Scripts\Player\WeaponSwitcher.cs(78,26): error CS0115: 'WeaponSwitcher.OnPlayerPropertiesUpdate(Player, Hashtable)': no suitable method found to override
0 -
Yeah so just go underneath that part, and do exactly what I've done below
type it all out, and you should get a auto fill for this. Then just delete the previous one!
0 -
dont worry i managed to find a solution.
dont know how or why but it works now.
i will post script.
using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Realtime;
using Hashtable = ExitGames.Client.Photon.Hashtable;
public class WeaponSwitcher : MonoBehaviourPunCallbacks
{
[SerializeField] GameObject[] items;
int itemIndex;
int previousItemIndex = -1;
[SerializeField] PhotonView view;
void Start()
{
if (view.IsMine)
{
EquipItem(0);
}
else
{
}
}
void Update()
{
for (int i = 0; i < items.Length; i++)
{
if (Input.GetKeyDown((i + 1).ToString()))
{
EquipItem(i);
break;
}
}
if (view.IsMine)
{
if (Input.GetAxisRaw("Mouse ScrollWheel") > 0f)
{
if (itemIndex >= items.Length - 1)
{
EquipItem(0);
}
else
{
EquipItem(itemIndex + 1);
}
}
else if (Input.GetAxisRaw("Mouse ScrollWheel") < 0f)
{
if (itemIndex <= 0)
{
EquipItem(items.Length - 1);
}
else
{
EquipItem(itemIndex - 1);
}
}
}
}
void EquipItem(int _index)
{
if (_index == previousItemIndex)
{
return;
}
itemIndex = _index;
items[itemIndex].SetActive(true);
if (previousItemIndex != -1)
{
items[previousItemIndex].SetActive(false);
}
previousItemIndex = itemIndex;
if (view.IsMine)
{
Hashtable hash = new Hashtable();
hash.Add("itemIndex", itemIndex);
PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
}
}
public override void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps)
{
if (!view.IsMine && targetPlayer == view.Owner)
{
EquipItem((int)changedProps["itemIndex"]);
}
}
}
0