Unity3d--some camera properties and camera follow

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:
  1. Select the camera on the Hierarchy panel, and a preview window will appear in the Scene view
    Insert picture description here

  2. According to the position of the camera moving axially, rotate the angle of the camera
    Insert picture description here

  3. GameObject–> Align With View (Ctrl + Shift + F) to its view

  4. 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)
    Insert picture description here
    2.Background 【background color】

  • When CLear Flag is Solid Color, the background color of the scene
    Insert picture description here
    3. Projectction [Projection]

  • Perspction: Perspective mode, 3D game use

  • Orthographic: Orthographic mode, 2D games use
    Insert picture description here
    4.Clipping Planes [cutting plane]

  • Near: Near plane, what the camera can see recently

  • Far: far plane, what the camera can see farthest

Insert picture description here

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

Insert picture description here

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
Insert picture description here
Insert picture description here

Published 65 original articles · 52 praises · 6213 visits

Guess you like

Origin blog.csdn.net/qq_42577542/article/details/105256497