Hello Guest

Author Topic: sprite on top of a 3d character  (Read 4713 times)

hich4m@gmail.com

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
sprite on top of a 3d character
« on: November 22, 2012, 01:05:12 pm »
Hello there
ok here is the situation

i have a top view perspective camera in a scene with some GameObjects, and another tk2dCamera that i use for the UI , so far everything works perfect .
what i want to do is display some sprites right on top of each game object , is there a way to do this with 2dToolKit ?

well there is also a problem since i need to instantiate dynamically the sprites depending on the number of those game objects .

any help would be much much appreciated , thanksssss

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: sprite on top of a 3d character
« Reply #1 on: November 22, 2012, 02:14:10 pm »
There is more than one solution to this.

The easiest, is to create a behaviour which will make the sprite face the camera always, and call MakePixelPerfect on it every frame.

The second is to put your sprites in the tk2dCamera scene, get the position from the perspectivecamera, use camera.WorldToScreenPoint to get a screen point, and then use tk2dCamera.ScreenToWorldPoint to transfer the coordinate to the tk2dCamera. You will need to adjust the z coordinate, but now the sprite can just be in the tk2dCamera, just use this logic to reposition every frame.

If you want to instantiate sprites, create a prefab and instantiate them.

hich4m@gmail.com

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: sprite on top of a 3d character
« Reply #2 on: November 22, 2012, 02:57:55 pm »
Thank you so much , i did the second method and it worked like a charm .
i have now my sprites as prefabs and instantiate and destroy them when i want :)

thats very cool