- Home /
Sniper zoom with texture
I need help getting a crosshair texture to show only when I am pressing the scope button. I have the script where I can zoom in like a sniper and see further away but I need a crosshair to cover the sides and make it look like a circle shape with a cross in the middle. Here is a picture as an example.
Here is my script.
public Texture sniperScope;
void Update (){
float altFieldOfView = 60.0f;
float ZoomLevel = 10.0f;
if(Input.GetMouseButtonUp(1)) {
float temp = camera.fieldOfView;
camera.fieldOfView = altFieldOfView;
altFieldOfView = temp;
}
if(Input.GetMouseButtonDown(1)) {
float temp = camera.fieldOfView;
camera.fieldOfView = ZoomLevel;
ZoomLevel = temp;
}
}
Answer by EvilSquid · Aug 17, 2013 at 03:07 PM
You can usually find free to use scopes etc on Google, or you can create one yourself using something like Photoshop if you want.
In terms of making it show up when you press the button, make sure that the GUI is a child of the camera, or whatever your script is attached to and try something like:
void Crosshairs()
{
crosshair.enabled = !crosshair.enabled
}
You can then call the function when you press your mouse button, so in your case:
if(Input.GetMouseButtonDown(1))
{
crosshairs();
}
if(Input.GetMouseButtonUp(1))
{
crosshairs();
}
I'm still a newbie to scripting, so that is probably not even close to right, but I hope this helped a little!
Answer by Mimumu84 · Aug 17, 2013 at 03:06 PM
You can create a GUI texture and enable/disable it inside the script with GUITexture.enabled = true/false
var scopeTexture : GUITexture; function Update() { if(Input.GetMouseButtonDown(1)) { scopeTexture.enabled = true; } if(Input.GetMouseButtonUp(1)) { scopeTexture.enabled = false; } } sorry that this is in JS but i think the syntax is a bit similar
Your answer
Follow this Question
Related Questions
Sniper zoom when right click? 1 Answer
Scoping script /Camera zoom preferably C# 3 Answers
Sniper scope zoom variances 0 Answers
FPS sniper zoom effect without black texture? 3 Answers
how do you zoom with a sniper? 5 Answers