Hello Guest

Author Topic: Zoom Factor and resize of UI Button  (Read 4507 times)

cmeynard

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 1
    • View Profile
Zoom Factor and resize of UI Button
« on: January 19, 2014, 01:33:54 pm »
Using Unity 4 and 2dToolkit (latest version, just purchased a couple of days ago)

Very new to 2D Toolkit and  still finding my way around.

(Existing)
I have a finished game that was creating too many draw calls. I am now adding the 2D Toolkit for batching. My issue is that I have yet to make one button work (yeshhh). I had a simple GUIbutton on the Main Camera. It is a zoom button that changes the ortho field. This button remains the same size throughout the process.

(New)
Created a 2dToolkit and sprite sheet with zoom image. Created a basicButton in 2dtoolkit. Assigned sprite (awesome). Created a HUD empty game object to hold scripts. When the basicButton is pushed it calls the script in HUD to resize the tk2dCamera zoom factor (awesome). Attached the button on to the camera so it is always in correct position in camera (awesome). Click on the button and the zoom factor changes (awesome) BUT the button also changes size which is not the desired effect. Regardless of the zoom factor the button needs to stay the same size as originally set on the camera. What am I doing wrong? This is perfect as a unity GUIButton.
Question: How do I maintain the button size when zoom factor changes?


Also, the button is on the lower right corner. When I change the zoom factor the button goes off screen even though it is attached to camera. The button needs to maintain position on camera. Again, what am I doing wrong? This was all cool in Unity GUI. (alas...no more hair to pull out). Starting to worry if this was a good purchase. Concerned about all of the other UI elements in game.

Question: How do you keep a button position relative to the camera when messing with zoom factor?
« Last Edit: January 19, 2014, 01:41:32 pm by cmeynard »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Zoom Factor and resize of UI Button
« Reply #1 on: January 19, 2014, 01:51:05 pm »
You'd just use a second camera for the gui. Use unity layers to make your gui draw only into the gui camera.  Unity gui basically creates a new projection matrix for gui which is why it isn't affected by rescaling - effectively a new camera. UI sample #3 - 3D UI has 2 cameras in there, useful for reference if you get stuck.