I’m trying to learn Unity with my son. Neither of us knows much about programming. So we’re following a tutorial and typing exactly what they have us type.
However, this created an error in the following code which we have no way to debug.
using UnityEngine;
using System.Collections;
public class cameraController : MonoBehaviour {
public GameObject player;
private Vector3 offset;
// Use this for initialization
void Start () {
offset = transform.position - player.transform.postion;
}
// Update is called once per frame
void LateUpdate () {
transform.position = player.transform.position + offset;
}
}
This script created the following error:
MissingReferenceException: The object of type ‘Object’ has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEditor.Editor.IsEnabled () (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:589)
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1151)
UnityEditor.InspectorWindow.DrawEditors (UnityEditor.Editor[ ] editors) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1028)
UnityEditor.InspectorWindow.OnGUI () (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:352)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[ ] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
One difference between the script in the tutorial and our script: In the tutorial, GameObject and Vector3 are both blue, while in our script they’re black. This suggests that those words are special in some way in the tutorial but not in our script.
Any ideas?