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

Check if a GameObject is active

Discussion in 'Scripting' started by aCake0202, Apr 22, 2021.

  1. aCake0202

    aCake0202

    Joined:
    Mar 11, 2021
    Posts:
    26
    Code (CSharp):
    1. public GameObject reloadTrigger;
    2. //other code
    3.  
    4.     public void CheckReloadMethod() {
    5.         if(reloadTrigger.activeSelf(false))
    6.         {
    7.  
    8.         }
    I'm just trying to check if a GameObject is active. Thought I had everything in order, but "activeSelf" is throwing "Non-invocable member 'GameObject.activeSelf' cannot be used like a method" and I have no idea what I'm doing wrong.
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,741
    What you're looking for is:
    Code (csharp):
    1. if (reloadTrigger.activeSelf == false) {
    Putting parentheses after it is what "invoking it like a method" means, and .activeSelf isn't a method.
     
    aCake0202 likes this.
  3. aCake0202

    aCake0202

    Joined:
    Mar 11, 2021
    Posts:
    26
    Awesome, thank you!