Home>
Sounds pretty cool,It's actually super simple.It is the fieldofview that controls the camera:
using unityengine;
using system.collections;
public class telesopicview:monobehaviour {
public float zoomlevel=2.0f;
public float zoominspeed=100.0f;
public float zoomoutspeed=100.0f;
private float initfov;
void start ()
{
//Get the field of view of the current camera
initfov=camera.main.fieldofview;
}
void update ()
{
if (input.getmousebutton (0))
{
zoominview ();
}
else
{
zoomoutview ();
}
}
//Enlarge the field of view of the camera
void zoominview ()
{
if (mathf.abs (camera.main.fieldofview-(initfov/zoomlevel))<3.0f)
{
camera.main.fieldofview=initfov/zoomlevel;
}
else if (camera.main.fieldofview-(time.deltatime * zoominspeed)>= (initfov/zoomlevel))
{
camera.main.fieldofview-= (time.deltatime * zoominspeed);
}
}
//Reduce the field of view of the camera
void zoomoutview ()
{
if (mathf.abs (camera.main.fieldofview-initfov)<3.0f)
{
camera.main.fieldofview=initfov;
}
else if (camera.main.fieldofview + (time.deltatime * zoomoutspeed)<= initfov)
{
camera.main.fieldofview +=(time.deltatime * zoomoutspeed);
}
}
}
Add the script telescopicview to the main camera. zoom level can adjust how far the view can be zoomed;zoom in speed adjust the zoom speed of the view;zoom out speed Adjust the speed of zoom out.
run game,When the left mouse button is pressed,The view will zoom in,When released, the view will slowly return to its original appearance:
Of course, in order to enhance the visual effect,You can also use the resource pack that comes with Unity.You can also design the telescope view picture yourself:
Tuning parameters,Run the game again.When the left mouse button is pressed,The view effect of the telescope is more realistic (added the effect of halo):
Trends
- python - you may need to restart the kernel to use updated packages error
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- javascript - how to check if an element exists in puppeteer
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file
- i want to check the type of a shell script variable
- i want to call a child component method from a parent in vuejs