NullReferenceException Unity
Есть 2 скрипта, и один ссылается на другой. Почему-то вылезает ошибка
NullReferenceException: Object reference not set to an instance of an object
Interact.Update () (at Assets/Scripts/Interact.cs:15)
В чем дело? Вот оба кода
using UnityEngine;
public class Interact : MonoBehaviour
{
public Transform book;
public float len;
void Update()
{
Vector3 offset = transform.position - book.position;
len = offset.sqrMagnitude;
if (len < 15 && GetComponent<Book>().isOver == true)
{
print("da");
}
}
}
using UnityEngine;
public class Book : MonoBehaviour
{
public bool isOver;
public void OnMouseOver()
{
isOver = true;
}
public void OnMouseExit()
{
isOver = false;
}
}