So some important things to let you guys know is this is in unity and this script is on a gameObject(the key). It casts a ray and then with
hitinfo.transform.SendMessage("interactedWithItem");
this function below is called from another script. I can state that the Debug.Log("this is a key")
is triggerd and shows in console, but for what ever reason the value of keyAmount isn't incremented. What am I doing wrong?
public int keyAmount;
public bool storableItem = true;
bool key = true;
//The function that will run if the storable item is set to true
public void interactedWithItem()
{
//Checks if the object is a key
if (key)
{
keyAmount++;
Debug.Log("is a key");
}
gameObject.SetActive(false);
}