Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Access GameObject of a static class ?

Discussion in 'Community Learning & Teaching' started by T4NK32, Sep 10, 2019.

  1. T4NK32

    T4NK32

    Joined:
    Aug 7, 2019
    Posts:
    16
    I'm trying to make a tower defense game. It's 3D but mostly viewed from above (2D).
    But if I right-click the mouse the camera can zoom and roam using WASD keys. This works.

    However, beside the playing field I have a sidebar where I pick which towers to build and so forth.
    But when in zooming/roaming the sidebar becomes useless, so I want to hide it.

    I'm trying to do that from the camera-script, so I added a script-component to the sidebar to make it static:
    Code (CSharp):
    1. using UnityEngine;
    2. public class SideBarManager : MonoBehaviour
    3. {
    4.     public static SideBarManager Instance;
    5.     void OnEnable() { Instance = this; }
    6. }
    In the camera-script I try the below to hide the sidebar (and everything on it):
    Code (CSharp):
    1. SideBarManager.Instance.GameObject.SetActive(false);
    error CS1061: 'SideBarManager' does not contain a definition for 'GameObject' : (
     
  2. T4NK32

    T4NK32

    Joined:
    Aug 7, 2019
    Posts:
    16
    Argh - GameObject is an instance of it's class and therefore spelled with a lowercase G:

    Code (CSharp):
    1. SideBarManager.Instance.gameObject.SetActive(false);