error CS0120 in Unity script

Hi guys,
I’m getting this error in unity:
Assets/Standard Assets/Scripts/General Scripts/ActivateTrigger.cs(53,52): error CS0120: An object reference is required to access non-static member `UnityEngine.GameObject.SetActive(bool)’

This code gives me the error:

break;
    				case Mode.Activate:
    					targetGameObject.SetActive(true); 
    					break;
    				case Mode.Enable:
    					if (targetBehaviour != null)
    						targetBehaviour.enabled = true;
    					break;	
    				case Mode.Animate:
    					targetGameObject.animation.Play ();
    					break;	
    				case Mode.Deactivate:
    					GameObject.SetActive = false;
    					break;

Hello,

When you are trying to access the GameObject your script is attached to, you need to put it in lower case: gameObject.
It’s the difference between accessing a recipe and a cake following the recipe (I like cake metaphors)

Another problem is that SetActive is a function, more specifically a method, so instead you have to call it and pass it either true or false, instead of trying to set it to true or false.
Usually, unless your using .NET classes, every variable in Unity is non-capitalised and every function/class is capitalised, so you know something is wrong when your trying to set something thats capitalised :slight_smile:

Hope this helps,
Benproductions1

Line 13, game object should be lower case and SetActive() is a method:

gameObject.SetActive(false);