using UnityEngine;
public class MoveCam : MonoBehaviour {
public GameObject Sphere;
public GameObject Camera;
public float xOffset = 1;
public float yOffset = 1;
public float zOffset = 1;
void Start () {
}
void Update () {
this.transform.position = new Vector3(Sphere.transform.position.x + xOffset, Sphere.transform.position.y + yOffset, Sphere.transform.position.z + zOffset);
}
}
Thank you!
Actually that code works perfectly… perhaphs you are not setting the Sphere variable in the inspector, or you dont have the script attached to your camera.
Something else, your camera variable is useless in this case, since you are using this.transform.position
. Otherwise use Camera.transform.position
though I’d recommend delete that variable since its a name used a lot by Unity and may cause errors.
You should try to avoid names such as: Object, Camera, Transform, etc.