- Home /
Destroy declaration but not game object
Hi. When i move mouse and my raycast give info that item is pickable i put him info item, by simply
public Rigidbody item;
RaycastHit hit;
item = hit.collider.GetComponent<Rigidbody>();
And i see what item im holding in unity window.
After i relise item (drop or throw) i want to make item unsigned again so i can pick other object/oher cube
(in unity "Item None (Rigidbody)" )
how can i unassinged item again? browse on internet but could find answer
Answer by Hellium · Nov 20, 2018 at 11:42 AM
Have you simply tried item = null
?
I thought i tryied but i didn't work(underlined expression i VS) but i tryied again and now works. really appreciate your help.
Answer by mlnczk · Nov 20, 2018 at 12:47 PM
private Rigidbody item; // we dont need to store item in inspector
Raycast hit;
if(hit.collider.GetComponent<Rigidbody>() != null){
item = hit.collider.GetComponent<Rigidbody>();
}
Try this. You check if object you hit has rigidbody, then locally you assaign item and it should overwrite next time.
It would overwrite if i hit other rigidbody. But i i hit for example sky i would have old rigidbody assign even thought its laying on the ground