Hi, I am currently trying to get my first game working with unity, I am following the “roll-a ball” tutorial but i cannot seem to get the camera working. It’s probably because the tutorial was recorded using an outdated version of the engine but stil I cant figure out how to get it working. Here is the code:
using UnityEngine;
using System.Collections;
public class CameraControl : MonoBehaviour
{
public GameObject Player;
private Vector3 offset;
// Use this for initialization
void Start ()
{
offset = transform.position;
}
// Update is called once per frame
void LateUpdate ()
{
transform.position = Player.transform.position + offset;
}
}
Here’s a my version of the code and I’m using Unity 5:
using UnityEngine;
using System.Collections;
public class CameraController : MonoBehaviour {
public GameObject player;
private Vector3 offset;
// Use this for initialization
void Start () {
offset = transform.position;
}
// Update is called once per frame
void LateUpdate () {
transform.position = player.transform.position + offset;
}
}
I did a quick comparison of the codes and the only difference I spotted was the class name: you have it as CameraControl whereas, according to the tutorial, it should be CameraController. I don’t think it would have mattered if you did everything consistently using the name CameraControl instead of CameraController but that’s probably still worth checking!
I hope it helps a little at least! Instead of trying to figure out what went wrong, sometimes, for a small script like this, I find it easier to delete the script and remove the script component from the object and just start again. Good luck!