public class BoxBotInventory : MonoBehaviour {
public GameObject[] inventory = new GameObject[2];
public bool itemAdded;
public void AddItem(GameObject item)
{
bool itemAdded = false;
//find the first open slot in the inventory
for (int i = 0; i < inventory.Length; i++)
{
if(inventory *== null)*
{
inventory = item;
Debug.Log(item.name + " was added");
itemAdded = true;
break;
}
}
//Inventory full
if (!itemAdded)
{
Debug.Log(“Inventory was full - Item was not added”);
}
}
}
//trying to use the itemAdded bool to enable the CarriedBox sprite renderer
public class CarriedBox : MonoBehaviour {
public bool itemAdded;
// Use this for initialization
void Start ()
{
BoxBotInventory itemAdded = GetComponent();
gameObject.GetComponent().enabled = false;
}
// Update is called once per frame
void Update()
{
if (itemAdded == true)
{
gameObject.GetComponent().enabled = true;
Debug.Log(“Sprite Render has been enabled”);
}
* }*
}
@BabyBoyBassMaster
You get a reference to the other script but you fail to use it to actually get the bool. This is how you should do it:
public class BoxBotInventory : MonoBehaviour {
public GameObject[] inventory = new GameObject[2];
private bool itemAdded;
public void SetItemAdded(bool status) {
itemAdded = status;
}
public bool GetItemAdded() {
return itemAdded;
}
public void AddItem(GameObject item)
{
itemAdded = false;
//find the first open slot in the inventory
for (int i = 0; i < inventory.Length; i++)
{
if(inventory *== null)*
{
inventory = item;
Debug.Log(item.name + " was added");
itemAdded = true;
break;
}
}
//Inventory full
if (!itemAdded)
{
Debug.Log(“Inventory was full - Item was not added”);
}
}
}
//trying to use the itemAdded bool to enable the CarriedBox sprite renderer
public class CarriedBox : MonoBehaviour {
private BoxBotInventory box;
// Use this for initialization
void Start ()
{
box = GetComponent();
gameObject.GetComponent().enabled = false;
}
// Update is called once per frame
void Update()
{
if (box.GetItemAdded() == true)
{
gameObject.GetComponent().enabled = true;
Debug.Log(“Sprite Render has been enabled”);
}
}
}
You must be new to scripting because there was quite a few errors. Hopefully you learn with more experience. I recommend reading the references on Unity and watching lots of tutorials.