Question by
ninjixfatality · Mar 30, 2018 at 08:45 AM ·
unity 5button trigger eventsunassignedreferenceexcept
Unassigned ReferenceException variable with Button?
I'm doing a menu that pops up that's asking to recycle. Why is it the function for ThrowAway works but Recycle doesn't yet their the same function?
"The Error reads UnassignedReferenceException: The variable recyclePanel of InventorySlot has not been assigned. You probably need to assign the recyclePanel variable of the InventorySlot script in the inspector." (However, it is assigned since ThrowAway is working. )
using UnityEngine; using UnityEngine.UI;
public class InventorySlot : MonoBehaviour {
public Image icon;
public Button removeButton;
public Button Recycle;
public Button ThrowAway;
public GameObject recyclePanel;
Item item;
public void AddItem (Item newItem)
{
item = newItem;
icon.sprite = item.icon;
icon.enabled = true;
removeButton.interactable = true;
}
public void ClearSlot(){
item = null;
icon.sprite = null;
icon.enabled = false;
removeButton.interactable = false;
//recyclePanel.SetActive (false);
}
public void OnRemoveButton()
{
//InventoryUI.SetActive(true);
//recyclePanel.SetActive (!recyclePanel.activeSelf);
recyclePanel.SetActive (true);
Recycle.interactable = true;
ThrowAway.interactable = true;
}
public void OnRecycle()
{
OnThrowAway ();
}
public void OnThrowAway()
{
Inventory.instance.Remove (item);
recyclePanel.SetActive (false);
}
}
Comment
Your answer
Follow this Question
Related Questions
How to play animation in new scene on button press? 0 Answers
UI does not work in build 0 Answers
how to make a cube change color by clicking a button? 0 Answers
Can't access functions on my UI button 1 Answer
Hold to jump higher 0 Answers