我有一个控制相机的脚本。这是脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
public GameObject player;
private Vector3 offset;
// Start is called before the first frame update
void Start()
{
offset = transform.position - player.transform.position;
}
// Update is called once per frame
void LateUpdate()
{
transform.position = player.transform.position + offset;
}
}
我将脚本拖放到相机,它可以工作。但是我没有为相机添加任何变量,所以无法理解它是如何控制相机的?
例如 player.transform.position >> 这是玩家的位置。
但是 transform.position >> 这是控制相机。如何?不应该是像camera.transform.position这样的东西吗?
transform.position 是附加脚本的游戏对象的 transform.position。
这里脚本附加到 Camera 游戏对象,所以 transform.position 是 Camera 游戏对象的位置。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句