Automatically add GameObject/Prefab name to GUI label

Hi there,

I have an inventory system which has an automated ToolTip (a GUI label) that plays if craftItem is ticked and the crafted item is defined with a craftedItem : GameObject having my new crafted item prefab dragged to it.

My GUI for tool-tips work perfectly and only if an item is set to craft into something else, this GUI looks like this:

    	if(craftObject)
    	{
    		GUI.color = Color.black;
    		GUI.Label (Rect (Screen.width/2 - 75, 50, 150, 30), "Press C to Craft item!");
    		Debug.Log("ToolTip");
    	}

My question is, how would I get to print the name of what is about to be crafted (name of the prefab) without having to make a different possibility for every object with variables. I want “Press C to Craft item!” to be replaced with “Press C to Craft plank!” for instance.

Kind regards,

You can do it like this:

if(craftObject)
        {
           GUI.color = Color.black;
           GUI.Label (Rect (Screen.width/2 - 75, 50, 150, 30), "Press C to Craft "+craftObject.name+"!");
           Debug.Log("ToolTip");
        }
  }