Hi, I am building an inventory system and need some help.
I have two scripts I am working with. The first script contains a function that receives an int variable, then searches through an array in order to find the object that has a component that matches the variable. The function will then toggle a boolean in that object. That function is thus
public void foundItem(int symbolNum){
//Iterates through all the clue items based off the length of images there are
//If the itemNum = images[ itemNum - 1] you have found the item
//Set the item that you have found to isFound = true
//Set the newly found item image to a visible transpency
print ("Looking for item# "+symbolNum);
//If the clue value is the same as symbol value, proceed
GameObject[] clueSymbolGOs = GameObject.FindGameObjectsWithTag("ClueSymbol");
//We are now looking for the clueItem i that matches s (symbol number)
foreach(GameObject clue in clueSymbolGOs){
if(clue.GetComponent<ClueBehaviour>().getClueSymbol() == symbolNum){
print ("Found clue symbol game object # "+ symbolNum);
//clue.GetComponent<GUITexture>().texture = symbolHolder;
//this.gameObject.GetComponent<GUITexture> ().texture = images[itemNum];
clue.GetComponent<ClueBehaviour>().isFound = true;
clue.GetComponent<GUITexture>().color = new Color(1f, 1f, 1f, 1f);
}
}
}
I have a second script that, upon being triggered, is supposed to define the int in the function (symbolNum). I have been trying to find a way to get this to work, but have been unsuccessful. My current attempt looks like this
public class CluePickup : MonoBehaviour {
public GameObject Symbolmatch;
// Use this for initialization
void Start () {
}
void OnTriggerStay2D() {
if (Input.GetMouseButtonDown (0)) {
Symbolmatch = (GetComponent<ClueBehaviour>().foundItem(2));
Destroy (this.gameObject);
}
}
// Update is called once per frame
void Update () {
}
}
My only clue as to why this is not working is that I am getting a compile error stating “CluePickup(the second script)(16,25) cannot implicitly convert type ‘void’ to ‘UnityEngine.GameObject’” I am not sure how to make this work. Can anybody help me?