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;
}
}
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;
}
}