hi all, ok im pretty new to unity and im makeing a simple web app which basicly lets you look at a 3d model in the browser... the model is of a large city scape so the camera needs to be able to pan and rotate around it in all directions... i have managed to get it to rotate and zoom the way i want it too but i have 2 problems 1. The way i do it at the moment is like this Code (csharp): var cam : Transform; var pivot : Transform; var controll: Transform; var image_rotate : Texture2D; var image_pan : Texture2D; var image_zoom : Texture2D; var image_reset : Texture2D; var customButton : GUIStyle; private var zoom = 0 ; private var rotx = 45 ; private var panx = 0 ; private var panz = 0 ; private var moveDirection = Vector3.zero; function OnGUI () { // Make a background's GUI.Box (Rect (545,6,49,58), image_rotate,customButton); GUI.Box (Rect (545,70,49,58), image_pan,customButton); GUI.Box (Rect (545,134,49,58), image_zoom,customButton); GUI.Box (Rect (545,198,49,58), image_reset,customButton); //make buttons //rotate buttons //up if (GUI.Button (Rect (560,3,18,18), "")) { print ("rotate up pressed"); if (rotx<80){ pivot.Rotate(5,0,0); rotx+=5; }else {print ("rotate maxed");} } //down if (GUI.Button (Rect (560,39,18,18), "")) { print ("rotate down pressed"); if (rotx>15){ pivot.Rotate(-5,0,0); rotx-=5; }else {print ("rotate mined");} } //left if (GUI.Button (Rect (542,21,18,18), "")) { print ("rotate left pressed"); controll.Rotate(0,5,0); } //right if (GUI.Button (Rect (578,21,18,18), "")) { print ("rotate right pressed"); controll.Rotate(0,-5,0); } //zoom buttons //up if (GUI.Button (Rect (550,10+128,40,20), "")) { print ("zoom up pressed"); if (zoom<500){ cam.Translate(0,0,20); zoom+=20; }else {print ("zoom mined");} } //down if (GUI.Button (Rect (550,30+128,40,20), "")) { print ("zoom down pressed"); if (zoom>-100){ cam.Translate(0,0,-20); zoom-=20; }else {print ("zoom maxed");} } } the problem is that the code is only exicuted when i relese the button... is there a way to do it so that the code is exicuted the entire time the button is being pressed? 2. Ok the other problem I'm having is with "panning" , the way i have set my objects up means that the "controll" object's x and z are always horizontal and facing the right way... so translation should be easy but i want to put a limit on it. the way i currently move is just using the FPS walker and then i have an object that i use an invisible wall around the limits. but i need a way to ether convert the pressing of the GUI button to the way the charactercontroller.move works or some other way to limit the movement... thanks for reading and any help p.s. this is one of my first unity projects and first time I'm using javascript, up until now I've been slashing together stuff from the standard assets and the help files so let me know if there is a better way to do this. cheers HamsterHill
1. Gui.RepeatButton 2. Not sure I quite understand the question, but Mathf.Clamp is a good way to limit numbers to certain ranges. --Eric
wow, thanks for the quick reply... that solved my first problem. what i mean for the secound one is basicly i want to basicly use the FPS walk script but i want to change the input from the WASD too gui buttons, how do i do that? cheers hamster
You could change that script so instead of using "Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));" you could use variables like "Vector3(horizontal, 0, vertical);" and then set the horizontal and vertical variables depending on the state of the appropriate GUI buttons. --Eric