Hi all
i need some input on why field of view is not updating on android device .
i am using fov to achieve zooming and it works perfectly in play mode on the editor
but its not working on android.
I am using the tutorial found here
And this is how i have adapted it into my project
I added a camera reff in script to have more control because i am working with 2 cameras active for vr.
other edits was to switch from screen.width/height to pixelwidth/height. etc…
Even when i try to have a native set up with 1 main active camera the zoom only works in editor and not on device.
Without any further knowledge to what might be causing the problem. i am left thinking its a device issue
maybe i need to add aspect ratio calculation in zoom script i tried and failed parts of it are commented out in the code
Am also thinking fov or main camera might be different on device and have no clue how to accesses them
Am also thinking maybe view-port data could be added in script but beyond basics i cant figure out where and how to add it effectively
before further making my code more messy and complex i decided to get some feed back from you all
THANKS all input are welcome and appreciated
var caml : Camera;
var camr : Camera;
var crosshairTexl : Texture2D; //crosshair images go here
var crosshairTexr : Texture2D; //crosshair images go here
var crosshairTexl1 : Texture2D; //crosshair images go here
var crosshairTexr1 : Texture2D; //crosshair images go here
var crosshairTexl1d : Texture2D; //crosshair images go here
var crosshairTexr1d : Texture2D; //crosshair images go here
var zoom : int = 2; //determines amount of zoom capable. Larger number means further zoomed in
var normal : int = 60; //determines the default view of the camera when not zoomed in
var smooth : float = 5; //smooth determines speed of transition between zoomed in and default state
public var zoomedIn = false; //boolean that determines whether we are in zoomed in state or not
public var fieldOfView = 60f;
var positionl : Rect; //position of the crosshair image
var positionr : Rect; //position of the crosshair image
static var OriginalOn = true;
function Start(){
caml.fieldOfView = Mathf.Lerp(caml.fieldOfView ,zoom,Time.deltaTime*smooth);
camr.fieldOfView = Mathf.Lerp(camr.fieldOfView ,zoom,Time.deltaTime*smooth);
}
function Update(){
//caml.fieldOfView = fieldOfView * (16f/9f) / (caml.pixelWidth / caml.pixelHeight);
//camr.fieldOfView = fieldOfView * (16f/9f) / (camr.pixelWidth / camr.pixelHeight);
positionl = Rect((caml.pixelWidth - crosshairTexl.width) / 2, (caml.pixelHeight - crosshairTexl.height) /2, crosshairTexl.width, crosshairTexl.height); //determines width/height of our crosshair GUI texture
positionr = Rect((camr.pixelWidth*2.99f - crosshairTexr.width) / 2, (camr.pixelHeight+0.2 - crosshairTexr.height) /2, crosshairTexr.width, crosshairTexr.height); //determines width/height of our crosshair GUI texture
if(Input.GetButtonDown("Fire2"))//(Input.GetKeyDown("z"))
{ //This function toggles zoom capabilities with the Z key. If it's zoomed in, it will zoom out
zoomedIn = !zoomedIn;
}
if(zoomedIn == true){ //If "zoomedIn" is true, then it will not zoom in, but if it's false (not zoomed in) then it will zoom in.
crosshairTexl = crosshairTexl1; //crosshair images go here
crosshairTexr = crosshairTexr1; //crosshair images go here
GetComponent(Camera).fieldOfView = Mathf.Lerp(caml.fieldOfView ,zoom,Time.deltaTime*smooth);
//camr.fieldOfView = Mathf.Lerp(camr.fieldOfView ,zoom,Time.deltaTime*smooth);
}
else{
GetComponent(Camera).fieldOfView = Mathf.Lerp(caml.fieldOfView,normal,Time.deltaTime*smooth);
//camr.fieldOfView = Mathf.Lerp(camr.fieldOfView,normal,Time.deltaTime*smooth);
crosshairTexl = crosshairTexl1d; //crosshair images go here
crosshairTexr = crosshairTexr1d; //crosshair images go here
}
}
function OnGUI()
{
if(OriginalOn == true)
{
GUI.DrawTexture(positionl, crosshairTexl); //"draws" crosshair texture
GUI.DrawTexture(positionr, crosshairTexr); //"draws" crosshair texture
//Cursor.visible = false; //disables cursor from being visible
}
}