- Home /
Moving camera around with GUI buttons
Howdy all,
I have a VERY simple GUI that moves my main camera through my scene. It functions by having a camera that is a child of a sphere in the scene. The sphere is caused to rotate by the GUI and the camera then moves, focused on the sphere. This is in no way ideal, but I am a a short time frame and its the best a beginner can come up with. I am wondering now, how would I add a zoom function to the following GUI:
Code:
var imageLeft: Texture2D;
var imageRight: Texture2D;
var imageUp: Texture2D;
var imageDown: Texture2D;
var speed: float = 60;
private var rotLeft = false;
private var rotRight = false;
private var rotUp = false;
private var rotDown = false;
var w1:float;
var x1:float;
var y1:float;
var z1:float;
var w2:float;
var x2:float;
var y2:float;
var z2:float;
var w3:float;
var x3:float;
var y3:float;
var z3:float;
var w4:float;
var x4:float;
var y4:float;
var z4:float;
function OnGUI(){
rotLeft = GUI.RepeatButton(Rect(w1,x1,y1,z1),
imageLeft); rotRight = GUI.RepeatButton(Rect(w2,x2,y2,z2), imageRight); rotUp = GUI.RepeatButton(Rect(w3,x3,y3,z3), imageUp); rotDown = GUI.RepeatButton(Rect(w4,x4,y4,z4), imageDown); }
function Update(){
if (rotLeft) transform.Rotate(0, -speed*Time.deltaTime, 0);
if (rotRight) transform.Rotate(0, speed*Time.deltaTime, 0);
if (rotDown) transform.Rotate(0, 0, speed*Time.deltaTime);
if (rotUp) transform.Rotate(0, 0, -speed*Time.deltaTime);
}
Or if anyone has any other suggestions for a GUI based controller I would be glad to hear them. The idea though is that the camera will orbit an object and constantly be looking at it. The only reason there are so many variables for the positioning of the buttons is aesthetics. I like to be able to move things around to see where they look best.
Thanks a ton, Richard
I believe there is a effect that can be uswd to smooth it out but i cant look it up Tm as i am not at home
tip:
When using variables to store x and y position, width and height dimensions, even for several rectangles ins$$anonymous$$d of one variable for each item, use for example:
var pos1: Vector2; (which comes with attributes x and y) var dim1: Vector2; (using x and y with width and height)
or
var rect1: Rect, you already defines a rectangle.
and when several values vectors use at least
var pos: Vector2 []; var dim: Vector2 [];
var rectangle: Rect [];
Answer by bodec · Apr 18, 2012 at 02:21 PM
I beleave another if statement with something down the Z axis would be neededusing the transform.position.z(or the X) and then just set up by how much .5 perclick or on a repeat button like you have.
Answer by solo24601 · Apr 18, 2012 at 05:09 PM
Thanks for responding. Yeah, I'm trying to make it smooth. But so far I have only been able to make it move very jittery and jumpy. Not really adept at writing code as you can see.
Try $$anonymous$$athf.Lerp to smooth the movements.
Answer by solo24601 · Apr 19, 2012 at 08:13 PM
Thanks, HomeSpun. Will do. And when I get this figured out I will post the full code here.
Answer by solo24601 · Apr 19, 2012 at 08:13 PM
Thanks, HomeSpun. Will do. And when I get this figured out I will post the full code here.
Your answer
Follow this Question
Related Questions
pan camera by touch / gui button 0 Answers
Making GUI Buttons on a GUI Texture 1 Answer
Clicking Trigger 1 Answer
How to stretch a GUI texture over it's original size? 1 Answer
flickering lines when zooming fov (both GUI and ortho cameras). 2 Answers