0
\$\begingroup\$

When I first started to develop in Unity I followed the Unity Tutorial for the Space Shooter 2D game and used the knowledge from that to create something myself. Looking at it now it may not have been the best idea.

Currently my game is 2D but in a 3D environment where the camera is top down and I am trying to figure out how I can detect a collision between a UI Image and my Player GameObject.

Any help will be extremely appreciated!

\$\endgroup\$
1
  • \$\begingroup\$ Can you please elaborate what you want to do. It would be helpful to answer. For example if you want to shoot the enemy while touching on them, then you can use Raycast. \$\endgroup\$ – Shuvro Sarkar Aug 17 '16 at 20:16
1
\$\begingroup\$

Two ways to go about this:

  1. Use regular (3D) colliders for everything.
  2. Use 2D colliders for everything.

It doesn't particularly matter which you pick, although working with 2D colliders will create fewer potential problems if you don't plan to use that extra axis of movement. Your main problem right now seems to be picking one or the other physics model.

Generally, if you're using an image as a game element it isn't part of the UI. You would normally use a sprite instead. But, if your heart is set on using a UI image, you could match a collider's position and shape to it in the place where it appears to be. Or, you could move the world in line with the UI (assuming you're using the new Unity UI, not the old IMHUI). Really though, it will make more sense to use a sprite.

\$\endgroup\$
1
  • \$\begingroup\$ An additional layer to this, if mixing UI and non-UI objects, is to use a worldspace canvas so both occupy the same physical space. With other canvas modes, the UI image could visibly overlap the player while being a long distance away according to the physics engine. ;) \$\endgroup\$ – DMGregory Oct 31 '16 at 22:45

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.