Essentially im using a gameobject to store guns that the player has access to and there is a script that allows the player to pickup a weapon. however when the player picks up the weapon it doesnt disable the previous gameobject of the parent so the guns just pile on top of each other.
Sorry for the bad explination
How can this be done
Any help would be apreciated
So if i understood it right, you want to make the parent null for that object, its simple: transform.parent = null;
I did a similar thing a while back in my game. A solution that I found was this.
First, reference your game object to locate the object you want to enable/disable in the Start()
function. To do this, use:
m_GameObject = GameObject.Find("ObjectName");
afterward, you’d want to call some sort of function to disable the object, like so:
void EnableAndDisableObject()
{
if (m_GameObject.activeSelf)
{
m_GameObject.SetActive(false);
}
else (!m_GameObject.activeSelf)
{
m_GameObject.SetActive(true);
}
}
I set this function to be a toggle so if you need to reactivate it, you can call this same function again. Hope this helps!