Skip to main content
added 131 characters in body
Source Link
Jim U
  • 263
  • 1
  • 11

This sets GameObjects' visibility by name by enabling/disabling their MeshRenderer:

static public class Utility
{
    static public void SetVisible(string name, bool visibility = true)
    {
        GameObject.Find(name).GetComponent<MeshRenderer>().enabled = visibility;
    }
}

This makes the game object named "AnitaBath" visible by activating it

Utility.SetVisible("AnitaBath");

This makes the game object named "AnitaBath" invisible by deactivating it

Utility.SetVisible("AnitaBath", false);

Assumptions

This script assumes the GameObjects you are working with are active and contain a MeshRenderer component

This sets GameObjects' visibility by name by enabling/disabling their MeshRenderer:

static public class Utility
{
    static public void SetVisible(string name, bool visibility = true)
    {
        GameObject.Find(name).GetComponent<MeshRenderer>().enabled = visibility;
    }
}

This makes the game object named "AnitaBath" visible by activating it

Utility.SetVisible("AnitaBath");

This makes the game object named "AnitaBath" invisible by deactivating it

Utility.SetVisible("AnitaBath", false);

This sets GameObjects' visibility by name by enabling/disabling their MeshRenderer:

static public class Utility
{
    static public void SetVisible(string name, bool visibility = true)
    {
        GameObject.Find(name).GetComponent<MeshRenderer>().enabled = visibility;
    }
}

This makes the game object named "AnitaBath" visible by activating it

Utility.SetVisible("AnitaBath");

This makes the game object named "AnitaBath" invisible by deactivating it

Utility.SetVisible("AnitaBath", false);

Assumptions

This script assumes the GameObjects you are working with are active and contain a MeshRenderer component

Correct error: GameObject.Find does not find inactive GameObjects
Source Link
Jim U
  • 263
  • 1
  • 11

This sets GameObjects' visibility by name by activatingenabling/deactivating themdisabling their MeshRenderer:

static public class Utility
{
    static public void SetVisible(string name, bool visibility = true)
    {
        GameObject.Find(name).SetActiveGetComponent<MeshRenderer>(visibility);.enabled = visibility;
    }
}

This makes the game object named "AnitaBath" visible by activating it

Utility.SetVisible("AnitaBath");

This makes the game object named "AnitaBath" invisible by deactivating it

Utility.SetVisible("AnitaBath", false);

This sets GameObjects' visibility by name by activating/deactivating them:

static public class Utility
{
    static public void SetVisible(string name, bool visibility = true)
    {
        GameObject.Find(name).SetActive(visibility);
    }
}

This makes the game object named "AnitaBath" visible by activating it

Utility.SetVisible("AnitaBath");

This makes the game object named "AnitaBath" invisible by deactivating it

Utility.SetVisible("AnitaBath", false);

This sets GameObjects' visibility by name by enabling/disabling their MeshRenderer:

static public class Utility
{
    static public void SetVisible(string name, bool visibility = true)
    {
        GameObject.Find(name).GetComponent<MeshRenderer>().enabled = visibility;
    }
}

This makes the game object named "AnitaBath" visible by activating it

Utility.SetVisible("AnitaBath");

This makes the game object named "AnitaBath" invisible by deactivating it

Utility.SetVisible("AnitaBath", false);
Source Link
Jim U
  • 263
  • 1
  • 11

This sets GameObjects' visibility by name by activating/deactivating them:

static public class Utility
{
    static public void SetVisible(string name, bool visibility = true)
    {
        GameObject.Find(name).SetActive(visibility);
    }
}

This makes the game object named "AnitaBath" visible by activating it

Utility.SetVisible("AnitaBath");

This makes the game object named "AnitaBath" invisible by deactivating it

Utility.SetVisible("AnitaBath", false);