Unity3D tutorial 11 c # script camera control,
First create a script
Click Create a folder named C #
Click the folder to create a C # script
Create a file and double-click the file.
Start Script Editor
Void Start () is used to load a program during scenario running.
Void Update () is a program that can be considered to be executed once every call.
Write the first script below
Control camera movement
Using UnityEngine;
Using System. Collections;
Public class acc: MonoBehaviour
{
Int speed = 50;
Void Start ()
{
}
Void Update ()
{
Float x = Input. GetAxis ("Horizontal") * Time. deltaTime * speed; // move left and right
Float z = Input. GetAxis ("Vertical") * Time. deltaTime * speed; // move
// Move the main camera object
Transform. Translate (x, 0, z );
}
}
Input. GetAxis is the Input manager.
Click edit
Learn more about input Manager
The red part is the key information.
Horizontal is a parallel movement. Press the d key and the <--> direction key to translate.
Call Code
Input. GetAxis ("Horizontal ")
Time. deltaTime is the Time interval
Speed = 50; is the step size
Distance between left and right
Float x = Input. GetAxis ("Horizontal") * Time. deltaTime * speed; // move left and right
Float z = Input. GetAxis ("Vertical") * Time. deltaTime * speed; // move
// Move the main camera object
Transform. Translate (x, 0, z)
Finally, bind the script to the camera.
Drag and Drop
Unity3d camera details
Just as the scenes in a movie are used to present the story to the audience, the Unity camera is used to present the game world to players. You always have at least one camera in the scene, and you can also have multiple. Multiple Cameras can give you a dual split screen effect or create an advanced custom effect. You can let the camera move, or use physical components to control them. Almost anything you can think of can be turned into a camera, and you can use a typical or special camera type to suit your game style.
Camera
The camera is a device for players to capture and display the world. By customizing and operating the camera, you can make your game look different. In a single scenario, you can have an unlimited number of cameras. They can be set to be rendered in any order, rendered anywhere on the screen, or rendered only part of the screen.
Sf_2711512_2492.jpg (58.03 KB, downloads: 917)
Download the attachment and save it to the album.
Upload
Attribute
· Clear Flags indicates which part of the screen will be cleared. It is very convenient to use multiple cameras to depict different game scenes.
· When the Background is depicted with all elements in the lens and there is no sky box, apply the selected color to the remaining Screen
· Culling Mask Remove masks that contain or ignore the camera rendering Object layer. Assign a layer for your object in view
· Projection the simulated pivoting function of the camera for Projection Switching
· --> The Perspective camera will render objects in full Perspective mode.
· --> Orthographic orthogonal cameras will uniformly render objects in a way without a sense of attention
· Size: Specifies the Size of the camera's view when orthogonal is set.
· Field of view the camera's angle width and vertical angle.
· Clipping the distance between Planes cropping plane rendering from camera to start and stopping rendering.
· --> Near points start to depict the nearest point relative to the camera.
· --> Far points start to depict the farthest point relative to the camera.
· The normalized viewport rectangle uses four values to indicate where the camera's view will be drawn on the screen and uses the screen coordinate system (value 0-1 ).
· --> X: the starting point of the horizontal position to be drawn in the camera view
· --> Y camera view will be used to draw the starting point of the vertical position
· --> W (Width) Width of the Width that the camera outputs to the screen
· --> H (Height) Height
· The height of the camera output to the screen
· The camera position in the deep drawing sequence of Depth. A camera with a greater margin will be drawn on a camera with a smaller value.
· Rendering Path: Rendering Path. This option defines the Rendering method to be used by the camera.
· --> Use Player Settings Use the Player to set the camera to Use the rendering path set in any Player Settings
· --> Vertex illumination the rendering of all objects by the camera will be rendered as Vertex illumination objects.
· --> Forward: Quickly renders all objects in one channel for each material, as standard in Unity2.x.
· --> Deferred Lighting delay Lighting all objects will be drawn once without illumination, and the Lighting of all objects will be rendered together at the end of the rendering queue
.
· Target Texture for Unity Pro/Advanced only, see Render Texture. This page contains the output of the camera view. This reference property disables the rendering of the camera to the screen.
Details
Cameras are essential for displaying your game to players. They can be customized, scripted, or quilt-based to achieve almost any conceivable effect. For a puzzle game, you need to keep the camera in a static display of all viewing angles. For a first-person shooter game, you should take the camera as a sub-object of the player role and place it at a high level such as the role's eyes. For a racing game, you may want your camera to follow the player's vehicle.
520 520 novels 520 novels 520 5200 novels 5200 5200 novels 5200 novels Novels
Www.520books.com
Http://www.cnblogs.com/goodchenqing/
Http://blog.sina.com.cn/goodchenqing
Http://goodchenqing.bokee.com/
Http://blog.csdn.net/abc288abcd/article/category/2786567
You can create multiple cameras and assign different depths to each camera. The camera is drawn from low to high by depth. In other words, a camera with a depth of 2 will be drawn on a camera with a depth of 1. You can adjust the attribute values of the standard-view rectangle (refer to the attribute list above) to change its size and position on the screen. In this way, you can create multiple small windows, such as missile controllers, small map Windows, and rearview mirrors.