Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Hello. Some noob issues here

Discussion in 'Getting Started' started by TonyOrlando, Mar 9, 2015.

  1. TonyOrlando


    Mar 9, 2015
    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;
  2. Effervescent


    Mar 7, 2015
    Here's a my version of the code and I'm using Unity 5:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    4. public class CameraController : MonoBehaviour {
    6.      public GameObject player;
    7.      private Vector3 offset;
    9.      // Use this for initialization
    10.      void Start () {
    11.           offset = transform.position;
    12.      }
    14.      // Update is called once per frame
    15.      void LateUpdate () {
    16.           transform.position = player.transform.position + offset;
    17.      }
    18. }

    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!
  3. TonyOrlando


    Mar 9, 2015
    It worked, thanks