The camera (Camera) is used to observe the game world
. The observation area of the camera is called the "view cone". Objects within the scope of the "view cone" can be seen.
1. The basic operation of the camera:
-
Select the camera on the Hierarchy panel, and a preview window will appear in the Scene view
-
According to the position of the camera moving axially, rotate the angle of the camera
-
GameObject–> Align With View (Ctrl + Shift + F) to its view
-
Create a camera, right-click Camera on the Hierarchy panel
2. Camera-related attributes
1. Clear Flags 【Clear Flags】
-
Skybox: Skybox
-
Solid Color: fixed color (solid color)
2.Background 【background color】 -
When CLear Flag is Solid Color, the background color of the scene
3. Projectction [Projection] -
Perspction: Perspective mode, 3D game use
-
Orthographic: Orthographic mode, 2D games use
4.Clipping Planes [cutting plane] -
Near: Near plane, what the camera can see recently
-
Far: far plane, what the camera can see farthest
Third, the camera follows
1. First create a cube on the Hierarchy panel and make it move
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class move : MonoBehaviour {
public float speed = 0.3f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
transform.Translate(new Vector3(h, v, 0) * speed);
}
}
The camera is not following
2. We add a script component to the camera to make it follow the object movement
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class followmove : MonoBehaviour {
private Vector3 dis;
//这里的到的是游戏物体的Transform信息,因为,我们需要的到它的位置信息即可
public Transform GameCube;
// Use this for initialization
void Start () {
//通过向量运算,得到物体与相机之间的相对(也可能是绝对,我忘了叫啥了)位置
dis = GameCube.position - transform.position ;
}
// Update is called once per frame
void Update () {
//游戏物体的位置加上相对(绝对)位置,就是相机的位置
transform.position = GameCube.position-dis;
}
}
Note: Do n’t forget to bind game objects