4
\$\begingroup\$

I just watched this Video https://unity3d.com/learn/tutorials/projects/survival-shooter/player-health and tried to drag'n'drop the UI-Elements on the matching script, just like they did. But this is not working for me. If I hover the public field Unity shows up an error icon and I can't drop it there. If I set this UI-Element as prefab I can place it there, but it does not update the Element which is in the Scene when the Code is live. The Elements just gets an update after each restart. Can anybody explain to me why I cannot drag'n'drop my Object from the hierarchy to the public field?

enter image description here

enter image description here

enter image description here

\$\endgroup\$
  • \$\begingroup\$ pics please.... \$\endgroup\$ – Leggy7 Mar 30 '15 at 15:47
  • \$\begingroup\$ Added, the mouse icon is not in the screenshot, but it shows an error icon if I hover the public field \$\endgroup\$ – TobiasW Mar 30 '15 at 15:56
  • \$\begingroup\$ looks like your trying to add a gameobject to an Item field. You should drag your image file from the project view \$\endgroup\$ – Leggy7 Mar 30 '15 at 15:57
  • \$\begingroup\$ So how can I make it to a GUI image? I mean to I get something wrong? Because they do it just like I try to do in the video. At around 9:15 he starts to drag'n'drop the objects into the script. And yes I saw it now in the video, it is a game object, but why is this working for him but not for me? \$\endgroup\$ – TobiasW Mar 30 '15 at 15:59
  • \$\begingroup\$ And how should I do this with the Slider? I mean nothing works here, it's not just the image \$\endgroup\$ – TobiasW Mar 30 '15 at 16:04
1
\$\begingroup\$

Instead of creating a regular game object, create a UI Image ( New >> UI >> Image/slider/etc.).

The new Unity UI system has specifics that aren't available to normal game objects, so when you make them public they need an exact type to be dragged onto them.

This has been my experience at least, hope it helps.

\$\endgroup\$
  • \$\begingroup\$ that is not a regular gameobject. It is a canvas I guess \$\endgroup\$ – Leggy7 Apr 1 '15 at 7:16
  • \$\begingroup\$ Yeah it is just a Canvas with Child Element Image or Slider or whatever you want \$\endgroup\$ – TobiasW Apr 1 '15 at 12:35
  • \$\begingroup\$ In my code its working. I have using UnityEngine.UI; then in the class it is just a public Image imageName; and is allowing me to drag and drop. \$\endgroup\$ – G. Meadows Apr 2 '15 at 8:13
  • \$\begingroup\$ Are you using Unity 5? \$\endgroup\$ – TobiasW Apr 3 '15 at 13:47
  • \$\begingroup\$ Yes, but my project was originally made in 4.6. It works in both. \$\endgroup\$ – G. Meadows Apr 4 '15 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.