unity3d 相机跟踪代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class camerafollow : MonoBehaviour {
public GameObject targetobject;
private float distance;
// Use this for initialization
void Start () {
distance = transform.position.x - targetobject.transform.position.x;
}

// Update is called once per frame
void Update () {
float targetobjectx = targetobject.transform.position.x;
Vector3 newcamerapostion = transform.position;
newcamerapostion.x = targetobjectx+distance  ;
transform.position = newcamerapostion;
}
}

你可能感兴趣的:(unity3d 相机跟踪代码)