I got 2 Scripts (one on my player GameObject and one on a shoppingNPC GameObject).
I have the same class to store some properties declared in bot scripts:
[System.Serializable]
public class Item{
public string name;
public int costs;
public float _value;
public string itemClass;
public int slotNumber;
public Texture2D texture;
}
In my “Inventory” script (the one on the player) i have a function to buy an item which takes “Item _item” as a paramater. I want to call this function from the other script via “SendMessage”.
This is the function in the inventory script:
void BuyItem(Item _item){
if(_item.costs < rubyAmount){
}
else{
infoText.SendMessage("ShowText", "I need more Rubys...");
}
}
This is the function with the SendMessage:
void OnGUI(){
if(shopActive){
GUI.skin = shopSkin;
GUI.BeginGroup(menuAreaNormalized);
int buttonNumber = 0;
for(int i = 0; i < _itemClass.Length; i++){
for(int k = 0; k < _itemClass*.buyableItem.Length; k++){*
if(itemClass*.buyableItem[k].buyable){
if(GUI.Button(new Rect(firstButton.x,firstButton.y + 48 * buttonNumber, firstButton.width, firstButton.height), _itemClass.buyableItem[k].itemGUI)){*
* Debug.Log("Classnummer: " + i.ToString() + “; Itemnummer: " + k.ToString() + " pressed”);_
player.SendMessage(“BuyItem”, _itemClass.buyableItem[k].item);*
* }
buttonNumber++;
}
}
}
GUI.EndGroup();
}
}_
itemClass is an class storing the className and the item to buy. buyableItem is a class which stores all information needed to buy the item in the shop including the item of type “Item” (the class from the beginning).*
I can’t find an error but if I click on an item in the shop it says “MissingMethodException: The best match for method has some invalid parameter.”
Anyone can help me?
I had a similar issue in my project and the issue turned out to be ambiguity with the method name of a public method in another manager class. Both Classes had a LoadMap() method and changing the name of the notification was the only way I could get rid of the error
– Yarbius