As the title says, the camera in the project follows the object well in game view in unity editor, but won't work in the actual game file. In game file, only the LookAt function works, not the MoveTowards. Here is the script:
using UnityEngine;
using System.Collections;
public class MiscaCamera : MonoBehaviour {
public new Transform camera;
public Transform rb;
public float viteza;
Vector3 dif;
void Start () {
viteza = GetComponent();
rb = GetComponent();
camera = GetComponent();
dif = camera.transform.position - rb.transform.position;
}
// Update is called once per frame
void FixedUpdate () {
camera.transform.LookAt(rb);
camera.transform.Translate(rb.transform.position - dif);
}
}
Where "viteza" means speed. I used this kind of movement because the object is set to move with time.deltaTime. Thanks.
↧