Push a UI-Element away with another

Hey guys,

I already tried the forums, but no success.

I work with the new UI system. And I heavily need to push a ui (RectTransform) away with another RectTransform.
So, some kind of collision in UI-Land.

Could you give me an example on how to do this or point me to a good tutorial?
I tried colliders, but didn’t got them to do this.

I have both elements as prefabs, however I do everything in code, so I’d prefer to do everything in code.

Any help is very appreciated.

This is not natively supported by the UI system.

The best way to do this would be to fake it. Have normal physics2D (or physics) colliders and rigidbodies attached. You may need to play around with several of the following options. Try them in this order. I present multiple options because I have not yet tried to do this myself, I’m not sure what conflicts will arise.

  • Attatch the physics components directly to the UI elements
  • Have the physics components as parents of the UI elements
  • Use a script to position the UI to match the physics position every frame