Can anyone tell me what’s wrong with this script?
using UnityEngine;
using System.Collections;
public class pickUp : MonoBehaviour
{
public float distance = 1f;
void Update()
{
Vector3 fwd = transform.TransformDirection(Vector3.forward);
RaycastHit hit;
if (Physics.Raycast(transform.position, fwd, distance) && hit.transform.tag == "Baby")
{
print("Something is a baby in front of the player?");
}
}
}
I’m getting this error:
NullReferenceException: Object reference not set to an instance of an object
pickUp.Update () (at Assets/Scripts/pickUp.cs:13)
Hit is underlined in Visual Studio with this error.
If anyone could help, that would be great! Thanks.