📜  相机跟随玩家团结 - 无论代码示例

📅  最后修改于: 2022-03-11 15:00:19.034000             🧑  作者: Mango

代码示例3
using UnityEngine;
using System.Collections;

public class Camera_Follow : MonoBehaviour
{
public GameObject player;
private Vector3 offset;
private Vector3 newtrans;

void Start ()
{
    offset.x = transform.position.x - player.transform.position.x;
    offset.z = transform.position.z - player.transform.position.z;
    newtrans=transform.position;
//not taking y as we wont update y position. 

}

void LateUpdate ()
{
newtrans.x= player.transform.position.x + offset.x;
newtrans.z= player.transform.position.z + offset.z;
transform.position = newtrans;
}
}