public static InteractionObject interactionObject;
public bool currentInterObj;
public bool inventory; //If true this object can be stored in inventory
public bool openable; //If true this object can be opened
public bool locked; //If true the object is locked
public GameObject itemNeeded; //Item needed in order to interact with this item
public void DoInteraction()
{
//Picked up and put in inventory
gameObject.SetActive (false);
}
public void Locked()
{
if(currentInterObj.locked)
{
gameObject.SetActive (false);
}else{
gameObject.SetActive (true);
}
}
Some objects have properties so a string has a length string.length and a transform has a position transform.position. You have created an object called currentInterObj, which is of type bool (line 2). However, it doesn’t have a property of bool, which is what you are asking for in line 17.
It strikes me you are trying to make what is called a struct. You want an object to have all these properties, in which case you need to instantiate the object with those properties in the first place. The following is sample code that you could adapt for all your items.
using UnityEngine;
public class ItemManager : MonoBehaviour
{
void Start()
{
Item box = new Item();
box.currentInterObj = True;
box.inventory = true;
box.openable = true;
box.locked = false;
box.itemNeeded = null;
}
struct Item
{
public bool currentInterObj;
public bool inventory; //If true this object can be stored in inventory
public bool openable; //If true this object can be opened
public bool locked; //If true the object is locked
public GameObject itemNeeded; //Item needed in order to interact with this item
}
}
When you’ve done all that, you can refer to the properties of box in your game using box.openable, for instance.
There are some shortcuts you can take when creating a struct but I’ve kept this simple and this format works perfectly well for items in your game.
Given on the information you now provided, this is probably what you want to have:
public void Lock()
{
//first check if there even is an "itemNeeded":
if(itemNeeded == null)
return;
//set active Status of the current GameObject to be the opposite of the locked flag.
gameObject.SetActive(!itemNeeded.locked);
}
Please remember to mark correct answers as such and provide the line an error points to when you post an error.