does anyone have a script for somthing like using the scope on a sniper do i just need to do somthing like have a 2nd camera futher forward from my gun and when u press fire2/ right click it switchs camera but uses same shooting spawn point if so how would i script that camera move thing
if u could id prefer the script in C# if u cant dw any type will do
You can implement whatever kind of zoom you want. If you want a dolly-style zoom, then a second camera or simply moving your main camera forward would do and likewise, even displaying a full-screen render texture of the second camera would also be a solution. If you wanted an actual perspective zoom, you would change field of view.
With 2 cameras, you could swap cameras by enabling/disabling them:
//Somewhere in a MonoBehaviour class
public Camera cam1;
public Camera cam2;
//Somewhere else in the class
if(Input.GetButtonUp("Fire2")) {
cam1.enabled = !cam1.enabled;
cam2.enabled = !cam2.enabled;
}
As I stated, there are several different solutions, most of which discussed in the questions tagged zoom.
You don't need a second camera (although you may want one positioned to align with the scope/have a GUITexture drawn over it, etc. That's all up to you, though). All you need to do is have a look at the Camera class, where you can chose to either change the field of view or the camera's transform, depending on how you want the effect to look. If you search the answers site for "sniper," "fov," or "field of view" (or some permutation of the three) you'll get a lot of answers related to what you want, including this one that Jonas answered: link.
i made this out of the script u gave me but is there anyway of making the it actually zoom in like saying feild of view goes up by 2 every frame until it reaches a set number and vice versa sorry i got u doing all my work but im really learning thanks
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//Somewhere
float altFieldOfView = 60.0f;
float ZoomLevel = 10.0f;
//Somewhere else
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;
}
}
}