- Home /
How to disable the previous child object of a parent,How to disable previous child of a gameobject
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 :)
Answer by SellPet · Feb 11 at 05:58 PM
So if i understood it right, you want to make the parent null for that object, its simple: transform.parent = null;
Answer by LeviTM · Feb 11 at 11:55 PM
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!
Your answer
Follow this Question
Related Questions
For some akward reason bullet is moving in the wrong direction 1 Answer
Refer to object class is attached to 1 Answer
Creating laser gun effect. 1 Answer
Timing Between each Gun Shot 2 Answers
Character Rotation Doesn't work 0 Answers