Hello Guest

Author Topic: Anchoring a game object  (Read 3668 times)

Mutajon

  • Newbie
  • *
  • Posts: 6
    • View Profile
Anchoring a game object
« on: October 11, 2015, 11:08:12 am »
Hi,

Is there a way to anchor non-UI game objects to certain positions in the camera view (game view)?
If so, how? Adding an anchoring component to them did not work...
(using 2dtk camera of course)

Thanks!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Anchoring a game object
« Reply #1 on: October 14, 2015, 11:33:28 am »
The anchor components works relative to a camera, it won't work relative to another camera... You can implement something in code, where you use Camera.WorldToScreenPoint to get the world position relative to the GUI camera, and then Camera.ScreenToWorldPoint on the other camera. It is a lot more complicated if one of them is perspective...

Mutajon

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Anchoring a game object
« Reply #2 on: October 21, 2015, 11:26:39 am »
Hi,

Thanks for the reply. However, I did not ask if it will work with another camera - on the contrary - I am using the 2DTK camera, just want to anchor some non-UI game objects to it (e.g. I want to be able to anchor a certain character to a specific relative location on the screen - the same way I can do with a button).

Is there a way to do this(other than putting said character as part of a canvas)?

Thanks

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Anchoring a game object
« Reply #3 on: October 22, 2015, 10:32:01 am »
The tk2d camera will draw anything you put in it. You can just use the normal anchoring to anchor any 2d or 3D object. But the things is - I'm guessing your other objects aren't being drawn by the same camera? If they are, it'll just work - if not refer to my previous post.