Hi, im making a pick up system and im trying to make it so that once you have dropped the object its rigidbody turns on again. Here is the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class pickup : MonoBehaviour
{
public Transform hand;
public GameObject fpscam;
public float range;
public float ThrowForce;
public RaycastHit hit;
public void Pick()
{
if (Physics.Raycast(fpscam.transform.position, fpscam.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);
Pickable target = hit.transform.GetComponent<Pickable>();
if (target != null)
{
target.transform.position = hand.transform.position;
hit.transform.SetParent(hand);
hit.rigidbody.isKinematic = true;
//Full = true;
}
}
}
public void Drop()
{
hand.transform.DetachChildren();
hit.rigidbody.isKinematic = false;
}
}
Im getting 2 errors:
NullReferenceException: Object reference not set to an instance of an object
pickup.Drop () (at Assets/pickup.cs:34)
UnityEngine.Events.InvokableCall.Invoke () (at /Users/bokken/buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent.cs:180)
UnityEngine.Events.UnityEvent1[T0].Invoke (T0 arg0) (at /Users/bokken/buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent/UnityEvent_1.cs:63) UnityEngine.InputSystem.Utilities.DelegateHelpers.InvokeCallbacksSafe[TValue] (UnityEngine.InputSystem.Utilities.CallbackArray
1[System.Action`1[TValue]]& callbacks, TValue argument, System.String callbackName, System.Object context) (at Library/PackageCache/com.unity.inputsystem@1.3.0/InputSystem/Utilities/DelegateHelpers.cs:46)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr) (at /Users/bokken/buildslave/unity/build/Modules/Input/Private/Input.cs:120)
and
NullReferenceException while executing ‘started’ callbacks of ‘Player/Drop[/Keyboard/k]’
UnityEngine.InputSystem.LowLevel.NativeInputRuntime/<>c__DisplayClass7_0:<set_onUpdate>b__0 (UnityEngineInternal.Input.NativeInputUpdateType,UnityEngineInternal.Input.NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate (UnityEngineInternal.Input.NativeInputUpdateType,intptr) (at /Users/bokken/buildslave/unity/build/Modules/Input/Private/Input.cs:120)
although it only happens when i add the line
hit.rigidbody.isKinematic = false;
Please help!