- Home /
resetting the my default value for camera field of view
hello i have made a minimap for my game and ive got a vertical scroller so you can zoom in and out i was wondering how i would go about making a button that resets the camera.fieldofview and also resets the vertical slider this is probley easy but i am a noob and have tried everything i know. here is my code so far:
var fovMax : float = 180;
var fovMin : float = 1;
var sliderPos : Rect = Rect ( 10, 10, 300, 30 );
private var camFOV : float;
function Start () {
camFOV = camera.fieldOfView;
}
function OnGUI () {
camFOV = GUI.VerticalSlider( sliderPos, camFOV, fovMin, fovMax );
if(GUI.RepeatButton(Rect(Screen.width/2 -19 , Screen.height -50, 18, 18), "+")){
camera.fieldOfView = 21f;
}
}
function Update () {
if (!Mathf.Approximately (camFOV, camera.fieldOfView)) camera.fieldOfView = camFOV;
any help will be appreciated thankyou.
Answer by zmar0519 · May 01, 2011 at 11:55 AM
its acutally really easy, since you have the camFOV var, just go
if(GUI.Button(Rect(10, 10, 200, 25), "Reset"))
camera.main.feildOfView = camFOV;
that doesnt seem to work and i am not using the main camera as it is only my $$anonymous$$imap it doesn't seem to change
it actually works on my main camera zoo$$anonymous$$g in on my player when i add camera.main but not when i take out the main?
i can not move the field of view bar manualy in the inspector when the game is running that may be the problem.
Your answer
Follow this Question
Related Questions
Moving camera around with GUI buttons 4 Answers
field of view slider starting point 1 Answer
Is it possible to link a UI element to a gameobject? 1 Answer
TheWebExpert says: My GUI Button is not showing up on Camera Preview 2 Answers
Can the Camera be Positioned on the Game Screen through code? 0 Answers