ERROR: BCE0020 an istance of type 'UnityEngine' is required to access not static membet 'SetActive'
//Version of Unity 5.3.1f1//
function Start() { Invoke ("Toogle", (Random.Range(22.0, 22.5))); } function Toggle() { GameObject.SetActive = !GameObject.SetActive; Invoke ("Toogle", (Random.Range(22.0, 22.5))); }
//Please solve this problem, thanks//
Answer by AlexT_IH · Jan 26, 2016 at 07:08 AM
From what I understand from your code, you have two problems:
a) You have tried to use SetActive as a variable when it is a function.
b) You have used SetActive as a static function when it isn't.
You could add a boolean type member variable to your class, named toggleState
or some other similar name and simply store the value you want to pass to the SetActive function there.
Alternatively, you could use the gameObject.activeSelf
(note the lowercase 'g' here; gameObject
is a property representing the GameObject to which this script is attached.
More information about GameObject: GameObject Script Reference
More information about GameObject::SetActive(): SetActive() Reference
PS: Please use the 0101010 button when you want to post code, it will format your pasted code in a much more beautiful and easy-to-read manner.
PS2: Your string parameter when using Invoke() should be Toggle, AKA the name of your function.
Your answer
![](https://koobas.hobune.stream/wayback/20220612061659im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Activating an object after it's set as inactive? 0 Answers
failed to activate error 0 Answers
[Begginer] [Solved] How to solve a Null Reference Exception 1 Answer
question about CommandInvokationFailure: Unable to convert classes into dex format. 2 Answers
NullReferenceException randomly occurs 2 Answers