Passing an object to a function in OnDrop
Hi. I'm trying to make a quick access system for my inventory and I have encountered a problem in OnDrop. Basically, I want to detect which object has just been dropped on a quick access item slot, and I want to pass this object to a function that will display it properly. This is what I have so far:
public void OnDrop(PointerEventData eventData)
{
GameObject dropped = eventData.pointerDrag;
DisplayItem script = dropped.GetComponent<DisplayItem>();
Item item = script.item;
dropped.transform.SetParent(gameObject.GetComponent<Transform>());
dropped.GetComponent<RectTransform>().position = GetComponent<RectTransform>().position;
DisplayItemInQuickAccess quickAccess = (DisplayItemInQuickAccess)Instantiate(displayPrefab);
quickAccess.transform.SetParent(gameObject.transform);
quickAccess.transform.position = gameObject.transform.position;
Debug.Log(item.Name);
quickAccess.Prime(item); //display the object properly in a new way
Destroy(dropped); //destroy the old object
}
As you can see, I printed the name of an item right before passing it to quickAccess.Prime. The debug log line works good and it does print the name of the item correctly, so why does the function Prime() complain that the object is null when I try to execute it?
Your answer
Follow this Question
Related Questions
How do I allow 3rd Person Character Picking Up Objects within a range? 1 Answer
How do you create a generic function for custom types that are inherited from a generic class? C# 1 Answer
How to drop to specific position? 0 Answers
How To: Scene Change After Facebook Login? 1 Answer
How can i stop the stretch effect of a material when i add it to an object and then resize it 2 Answers