- Home /
Sniper Zooming
Hello guys, i'm trying to make a sniper game but i have some issues with the zooming.I have the code to change the FOV:
private var baseFOV : float;
function Start () {
baseFOV = Camera.main.fieldOfView;
}
function Update () {
if (Input.GetMouseButton(1))
Camera.main.fieldOfView = 10;
else
Camera.main.fieldOfView = baseFOV;
}
but i dont know how i can make it to show the crosshair/scope at the same time.(Note: i am not a programmer).Thanks in advance ;)
Answer by TheDarkVoid · Aug 22, 2012 at 04:26 PM
you can just render a texture that has the crosshair and scope onto the screen when you are zoomed in.
you can do the texture, and center it with this code:
var Texture : Texture2D;
function OnGUI ()
{
GUI.DrawTexture(Rect ((Screen.width/2)-(Texture.width/2), (Screen.height/2)-(Texture.height/2), Texture.width, Texture.height), Texture);
}
Answer by Cool Dave · Aug 22, 2012 at 05:15 PM
Put this code into your script and hook up your crosshair. It will not be centered, though, but I've never done any centering either. Look up Screen.width in the Scripting Reference. I think if you know basic math, you should be able to figure it out from that. Hope it works for you!
var textureToDisplay : Texture2D;
function OnGUI ()
{
GUI.Label (Rect (10, 40, textureToDisplay.width, textureToDisplay.height), textureToDisplay);
}
Your answer
Follow this Question
Related Questions
Sniper Scope with zoom 1 Answer
Sniper zoom 1 Answer
Lining up Fov's 0 Answers
Sensitivity Help? || Scope Zoom 1 Answer
Sniper scope zoom variances 0 Answers